Added PageComponents
This commit is contained in:
@@ -30,3 +30,23 @@ export function trailOf(article: Article): Article[] {
|
||||
for (let node: Article | null = article; node; node = node.parent) trail.unshift(node)
|
||||
return trail
|
||||
}
|
||||
|
||||
export type ContextGroup = {
|
||||
heading: Article | null
|
||||
entries: Article[]
|
||||
}
|
||||
|
||||
export function contextOf(article: Article | null, roots: Article[]): ContextGroup[] {
|
||||
if (!article) return [{ heading: null, entries: roots }]
|
||||
|
||||
const { parent } = article
|
||||
const siblings = (parent ? parent.children : roots).filter((entry) => entry !== article)
|
||||
|
||||
const groups: ContextGroup[] = [
|
||||
{ heading: parent?.parent ?? null, entries: parent?.listed ? [parent] : [] },
|
||||
{ heading: parent, entries: siblings },
|
||||
{ heading: article, entries: article.children },
|
||||
]
|
||||
|
||||
return groups.filter((group) => group.entries.length > 0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user