refactored prebuild
This commit is contained in:
parent
26accfdd2b
commit
5e7608f1c7
|
|
@ -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());
|
||||
Loading…
Reference in New Issue