404 Page
This commit is contained in:
35
src/lib/site/directory.ts
Normal file
35
src/lib/site/directory.ts
Normal 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)
|
||||
}
|
||||
@@ -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.'
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user