Blog/bun_plugins/onStartup-post-importer.ts

17 lines
555 B
TypeScript

import matter from 'gray-matter';
import { loadMetadata } from "./utils";
// When the server starts, import all the blog post metadata into the database
// Executed on startup because it's included in <root> ./bunfig.toml
(async () => {
const glob = new Bun.Glob("**/*.md");
for await (const file of glob.scan("./content")) {
const {data, content } = matter(await Bun.file(`./content/${file}`).text());
const route = `/${file.replace(/\.md$/, "")}`;
loadMetadata(route, data);
}
console.log('Posts have been imported into db');
})();