diff --git a/scripts/prebuild.mjs b/scripts/prebuild.mjs index 68b97df..ab19e8f 100755 --- a/scripts/prebuild.mjs +++ b/scripts/prebuild.mjs @@ -2,21 +2,20 @@ import {glob} from 'glob'; import fs from 'fs'; import fm from 'front-matter'; +const posts_dir = 'public/posts/'; + function loadStrings() { - const posts = glob.sync('public/posts/*.md').map((file) => { + const posts = glob.sync(`${posts_dir}*.md`).map((file) => { const content = fs.readFileSync(file, 'utf8'); + const slug = file.replace(`${posts_dir}`, '').replace('.md', ''); const { title, date, location } = fm(content).attributes; - const slug = file.replace('public/posts/', '').replace('.md', ''); return { date, slug, title, location }; }); - posts.sort((a, b) => new Date(a.date) - new Date(b.date)) - return posts; + return posts.sort((a, b) => new Date(a.date) - new Date(b.date)); } function saveStrings(posts) { - console.log(posts); - const jsonl = posts.map((post) => JSON.stringify(post)).join('\n'); - fs.writeFileSync('public/posts.jsonl', jsonl); + fs.writeFileSync('public/posts.jsonl', posts.map((post) => JSON.stringify(post)).join('\n')); } saveStrings(loadStrings()); \ No newline at end of file