diff --git a/index.js b/index.js index ccfac13..99c8bfc 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ const express = require('express'); +const matter = require('gray-matter'); const router = express.Router(); const { exec } = require('child_process'); @@ -59,7 +60,36 @@ router.get('/viewPost', (req, res) => { console.log(`stderr: ${stderr}`); return; } - res.send(stdout.split('\n').filter(Boolean)); + let post = matter(stdout) + let { title, author, timestamp } = post.data + let html="" + + if ( title ) { + html += `
${post.content}
` + res.send(html); + }); +}); + +router.get('/api/viewPost', (req, res) => { + let { filename } = req.query; + exec(`./routes/viewPost --filename=${filename}`, (error, stdout, stderr) => { + if (error) { + console.log(`error: ${error.message}`); + return; + } + if (stderr) { + console.log(`stderr: ${stderr}`); + return; + } + res.json(matter(stdout)); }); });