24 lines
793 B
TypeScript
24 lines
793 B
TypeScript
import { buildFileTree, extractHeadings, extractSection, type TocNode, type FileNode } from "./toc";
|
|
import {getIndexedData, getPathsByExtension} from "./file-index";
|
|
|
|
export { TocNode, FileNode, extractHeadings, buildFileTree, extractSection };
|
|
|
|
/**
|
|
* 生成目录树(文件树 + 标题结构)
|
|
* 仅处理 .md 文件
|
|
*/
|
|
export async function generateToc(): Promise<{ fileTree: FileNode[]; pathHeadings: Record<string, TocNode[]> }> {
|
|
const mdPaths = await getPathsByExtension("md");
|
|
const fileTree = buildFileTree(mdPaths);
|
|
const pathHeadings: Record<string, TocNode[]> = {};
|
|
|
|
for (const path of mdPaths) {
|
|
const content = await getIndexedData(path);
|
|
if (content) {
|
|
pathHeadings[path] = extractHeadings(content);
|
|
}
|
|
}
|
|
|
|
return { fileTree, pathHeadings };
|
|
}
|