Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | 17x 17x 3x 35x 9x 3x 9x 3x 28x 28x 3x 11x 11x 99x 11x 67x 11x 52x 61x 11x 11x 61x 61x 61x 11x 3x 3x 3x 2x 3x | <template>
<nav class="flex flex-col gap-5 text-sm">
<div v-for="section in sections" :key="section.id" class="flex flex-col gap-1">
<div
class="flex items-center gap-1.5 px-2 text-xs font-medium tracking-wide text-dimmed uppercase"
>
<UIcon :name="section.icon" class="size-3.5" />
{{ section.label }}
</div>
<div v-for="group in section.groups" :key="group.key" class="flex flex-col">
<NuxtLink
v-if="soleEntry(group)"
:to="`/wiki${soleEntry(group)?.path}`"
class="flex items-center gap-1 rounded-md px-2 py-1 font-mono text-xs transition-colors hover:bg-elevated/50"
:class="
soleEntry(group)?.path === current
? 'bg-elevated text-primary'
: 'text-muted'
"
>
<span class="size-3 shrink-0" />
<span class="flex-1 truncate">{{ group.label }}</span>
</NuxtLink>
<div
v-else
class="flex items-center gap-1 rounded-md px-2 py-1 text-xs text-muted transition-colors hover:bg-elevated/50"
>
<button
type="button"
class="flex shrink-0 items-center"
@click="toggle(section, group)"
>
<UIcon
:name="
isOpen(section, group)
? 'i-lucide-chevron-down'
: 'i-lucide-chevron-right'
"
class="size-3 text-dimmed"
/>
</button>
<NuxtLink
v-if="overviewPath(group)"
:to="`/wiki${overviewPath(group)}`"
class="flex-1 truncate font-mono transition-colors hover:text-primary"
>
{{ group.label }}
</NuxtLink>
<button
v-else
type="button"
class="flex-1 truncate text-left font-mono"
@click="toggle(section, group)"
>
{{ group.label }}
</button>
</div>
<NuxtLink
v-for="entry in isOpen(section, group) && !soleEntry(group)
? group.entries
: []"
:key="entry.path"
:to="`/wiki${entry.path}`"
class="flex items-center gap-2 rounded-md py-1 pr-2 pl-6 transition-colors hover:bg-elevated/50"
:class="
entry.path === current
? 'bg-elevated font-medium text-primary'
: 'text-default'
"
>
<UIcon :name="kindIcon(entry.kind)" class="size-3.5 shrink-0 text-dimmed" />
<span class="flex-1 truncate">{{ entry.label }}</span>
</NuxtLink>
</div>
</div>
</nav>
</template>
<script setup lang="ts">
import type { WikiEntry, WikiGroup, WikiSection } from "#layers/wiki/app/utils/wiki.ts";
interface Props {
sections: WikiSection[];
current?: string;
}
const { sections, current = "" } = defineProps<Props>();
const { t } = useI18n();
const holdsCurrent = (group: WikiGroup): boolean =>
group.entries.some((entry) => entry.path === current);
/** A group that is only its README is a link, not a folder holding one page called "Overview". */
const soleEntry = (group: WikiGroup): WikiEntry | null =>
group.entries.length === 1 ? (group.entries[0] ?? null) : null;
/** Every group lists its directory's own README first, so the group label doubles as a link to it. */
const overviewPath = (group: WikiGroup): string | null =>
group.entries.find((entry) => entry.label === t("wiki.overview"))?.path ?? null;
const opensByDefault = (group: WikiGroup): boolean => holdsCurrent(group);
// Which groups a click flipped away from their default, not which are open, so a group left alone
// keeps tracking `holdsCurrent` as the reader navigates.
const toggled = ref(new Set<string>());
const isOpen = (section: WikiSection, group: WikiGroup): boolean => {
const key = `${section.id}/${group.key}`;
const isDefault = opensByDefault(group);
return toggled.value.has(key) ? !isDefault : isDefault;
};
const toggle = (section: WikiSection, group: WikiGroup): void => {
const key = `${section.id}/${group.key}`;
const next = new Set(toggled.value);
if (next.has(key)) next.delete(key);
else next.add(key);
toggled.value = next;
};
</script>
|