refactored prebuild

This commit is contained in:
Orion Reed 2023-08-12 15:21:42 +01:00
parent 26accfdd2b
commit 5e7608f1c7
1 changed files with 6 additions and 7 deletions

View File

@ -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());