From 39e25839747f3fccf8821dd2d6c700358eaa7584 Mon Sep 17 00:00:00 2001 From: Aran Roig Date: Sat, 18 Jul 2026 19:03:30 +0200 Subject: [PATCH] More things --- template/app/components/TreeNode.vue | 82 +++++++++++++++++++++++++--- template/content/index.md | 57 ++++++++++++++++--- 2 files changed, 123 insertions(+), 16 deletions(-) diff --git a/template/app/components/TreeNode.vue b/template/app/components/TreeNode.vue index 93889b6..d30315a 100644 --- a/template/app/components/TreeNode.vue +++ b/template/app/components/TreeNode.vue @@ -4,7 +4,7 @@ import { useTreeState } from '~/composables/useTreeState' defineProps({ nodes: Array, depth: { type: Number, default: 0 } }) const router = useRouter() -const { collapsed } = useTreeState() // ← shared state, not local ref +const { collapsed } = useTreeState() function getTitle(node) { if (node.title === 'index') return 'Index' @@ -19,12 +19,37 @@ function navigate(path) { function toggle(key) { collapsed.value[key] = !collapsed.value[key] } + +/** + * If the folder contains a child whose path/title matches the folder itself + * (e.g. places/ has a child at places/places.md), return that child. + * Otherwise return null. + */ +function getSelfTitledChild(node) { + if (!node.children?.length) return null + const folderSlug = node.path?.split('/').pop() ?? node.title + return node.children.find((child) => { + const childSlug = child.path?.split('/').pop() ?? child.title + return childSlug === folderSlug + }) ?? null +} + +/** + * Children to actually render — excludes the self-titled child so it + * doesn't appear twice (once as the clickable folder label, once in the list). + */ +function visibleChildren(node) { + const selfTitled = getSelfTitledChild(node) + if (!selfTitled) return node.children + return node.children.filter((c) => c !== selfTitled) +}