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

${labelify(name)}

${ upload.description ? `

${upload.description}

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

No results

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