mirror of
https://github.com/kevin-DL/sapper-template.git
synced 2026-01-23 06:51:27 +00:00
create blog posts from markdown files
This commit is contained in:
@@ -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'
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user