27 lines
No EOL
1 KiB
TypeScript
27 lines
No EOL
1 KiB
TypeScript
import { AnalyzeMarkdown } from "./lib/markdown_analyzer.ts";
|
|
import { PageRoot } from "./lib/page.ts";
|
|
|
|
// Function to recursively crawl through the directory and analyze markdown files
|
|
async function analyzeMarkdownFiles(dir: string, pageInfo: PageRoot): PageRoot {
|
|
for await (const entry of Deno.readDir(dir)) {
|
|
const fullPath = `${dir}/${entry.name}`;
|
|
|
|
if (entry.isDirectory) {
|
|
// Recurse into subdirectories
|
|
pageInfo = await analyzeMarkdownFiles(fullPath, pageInfo);
|
|
} else if (entry.isFile && fullPath.endsWith(".md")) {
|
|
// Analyze markdown file
|
|
console.log(`Analyzing: ${fullPath}`);
|
|
pageInfo.articles.push(await AnalyzeMarkdown(fullPath));
|
|
}
|
|
}
|
|
|
|
return pageInfo;
|
|
}
|
|
|
|
// Start the crawling process from the `./articles` directory
|
|
const data = await analyzeMarkdownFiles("./articles", {
|
|
articles: []
|
|
});
|
|
|
|
Deno.writeFileSync("./meta.json", new TextEncoder().encode(JSON.stringify(data, null, 2)), {append: false}) |