refactored prebuild
This commit is contained in:
parent
26accfdd2b
commit
5e7608f1c7
|
|
@ -2,21 +2,20 @@ import {glob} from 'glob';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import fm from 'front-matter';
|
import fm from 'front-matter';
|
||||||
|
|
||||||
|
const posts_dir = 'public/posts/';
|
||||||
|
|
||||||
function loadStrings() {
|
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 content = fs.readFileSync(file, 'utf8');
|
||||||
|
const slug = file.replace(`${posts_dir}`, '').replace('.md', '');
|
||||||
const { title, date, location } = fm(content).attributes;
|
const { title, date, location } = fm(content).attributes;
|
||||||
const slug = file.replace('public/posts/', '').replace('.md', '');
|
|
||||||
return { date, slug, title, location };
|
return { date, slug, title, location };
|
||||||
});
|
});
|
||||||
posts.sort((a, b) => new Date(a.date) - new Date(b.date))
|
return posts.sort((a, b) => new Date(a.date) - new Date(b.date));
|
||||||
return posts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveStrings(posts) {
|
function saveStrings(posts) {
|
||||||
console.log(posts);
|
fs.writeFileSync('public/posts.jsonl', posts.map((post) => JSON.stringify(post)).join('\n'));
|
||||||
const jsonl = posts.map((post) => JSON.stringify(post)).join('\n');
|
|
||||||
fs.writeFileSync('public/posts.jsonl', jsonl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
saveStrings(loadStrings());
|
saveStrings(loadStrings());
|
||||||
Loading…
Reference in New Issue