import { labelify } from "../../utils/string.ts"; import { getPath } from "../../utils/path.ts"; import breadcrumb from "../breadcrumb.ts"; import createTree from "../tree.ts"; import type { Tree } from "../tree.ts"; import type Collection from "../../collection.ts"; import type { CMSContent, Version } from "../../../types.ts"; interface Props { options: CMSContent; collection: Collection; version?: Version; } export default async function template( { options, collection, version }: Props, ) { const documents = await Array.fromAsync(collection); const tree = createTree(documents); const content = folder({ options, collection, tree }).trim(); return ` ${breadcrumb(options, version, collection.name)}

${labelify(collection.name)}

${ collection.description ? `

${collection.description}

` : "" }
${ content ? `` : '

No results

' } `; } interface FolderProps { options: CMSContent; collection: Collection; tree: Tree; } function folder({ options, collection, tree }: FolderProps) { const folders: string[] = Array.from(tree.folders?.entries() || []) .map(([name, subTree]) => `
  • ${labelify(name)}
  • `); return ` ${folders.join("")} ${files({ options, collection, files: tree.files })} `; } interface FilesProps { options: CMSContent; collection: Collection; files?: Map; } function files( { options, collection, files }: FilesProps, ) { if (!files) { return ""; } return Array.from(files.entries()).map(([name, file]) => `
  • ${labelify(name)}
  • `).join(""); }