site-data/scripts/update.ts

27 lines
1 KiB
TypeScript
Raw Normal View History

2025-01-15 18:47:33 -08:00
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})