This commit is contained in:
2026-09-25 11:32:07 +02:00
parent 356ccedc01
commit d06f0293ce
15 changed files with 369 additions and 282 deletions

35
src/lib/site/directory.ts Normal file
View File

@@ -0,0 +1,35 @@
import type { DirectoryEntry, Site } from './types'
const depthOf = (path: string) => path.split('/').filter(Boolean).length
const byPath = (a: DirectoryEntry, b: DirectoryEntry) => a.path.localeCompare(b.path)
export function directoryOf(site: Site): DirectoryEntry[] {
const articles = [...site.articles.values()]
.filter((article) => article.listed)
.map((article) => ({
title: article.title,
path: article.path,
collection: article.collection,
parent: article.parent?.title ?? null,
depth: depthOf(article.path),
}))
const pages = [...site.pages.values()].map((page) => ({
title: page.title,
path: page.path,
collection: page.collection,
parent: null,
depth: depthOf(page.path),
}))
const tags = [...site.tags.values()].map((tag) => ({
title: tag.title,
path: tag.path,
collection: tag.collection,
parent: null,
depth: depthOf(tag.path),
}))
return [...articles, ...pages, ...tags].sort(byPath)
}

View File

@@ -15,7 +15,7 @@ export const isListed = (status: Status, { drafts }: Visibility) =>
export const segmentOf = (entry: { title: string; route: { segment: string } }) =>
entry.route.segment || slugify(entry.title)
const RESERVED = [TAGS, 'keystatic']
const RESERVED = [TAGS, 'keystatic', 'api']
export function segmentProblem(segment: string, atRoot: boolean): string | null {
if (!segment) return 'The title has no URL-safe character. Set an URL segment.'

View File

@@ -37,3 +37,11 @@ export type Site = {
roots: Article[]
diagnostics: Diagnostic[]
}
export type DirectoryEntry = {
title: string
path: string
collection: typeof ARTICLES | typeof PAGES | typeof TAGS
parent: string | null
depth: number
}