create blog posts from markdown files

This commit is contained in:
Rich Harris
2018-07-27 14:28:32 -04:00
parent 29e6481559
commit 0fa6c9f7d7
10 changed files with 129 additions and 98 deletions

View File

@@ -1,13 +1,17 @@
import posts from './_posts.js';
import { getPosts } from './_posts.js';
const contents = JSON.stringify(posts.map(post => {
return {
title: post.title,
slug: post.slug
};
}));
let contents;
export function get(req, res) {
if (!contents || process.env.NODE_ENV !== 'production') {
const posts = getPosts().map(post => ({
title: post.metadata.title,
slug: post.slug
}));
contents = JSON.stringify(posts);
}
res.writeHead(200, {
'Content-Type': 'application/json'
});