import type { PageSection } from "#types/writing.types"; import { readPageContent } from "#core/loaders/payload.loader"; import { sectionsOf } from "#core/converters/section.converter"; const PAGE_IDS_MODULE = "@banes-lab/web/core/ids/page.ids.ts"; export const sitePages = async function sitePages(): Promise { const ids: unknown = await import(PAGE_IDS_MODULE); return typeof ids === "object" && ids !== null ? Object.values(ids).filter((id: unknown): id is string => typeof id === "string") : []; }; export const readSections = function readSections(pages: readonly string[]): { readonly missing: readonly string[]; readonly sections: readonly PageSection[]; } { const found = pages.map((page) => ({ content: readPageContent(page), page })); return { missing: found.filter((entry) => entry.content === null).map((entry) => entry.page), sections: found.flatMap((entry) => (entry.content === null ? [] : sectionsOf(entry.page, entry.content))), }; };