I want to imitate jekyll
,build a blog with nodejs and express; I use the fs
module read the markdown
file and translate into html string;then I use res.render('view',{html:html})
to pass my html string ,but in the end it render as text,how can I do? render it into html..
router.get('/:year/:month/:day/:title', function (req, res) {
var fileName =
'../blogs/' +
req.params.year + '-' +
req.params.month + '-' +
req.params.day + '-' +
req.params.title + '.md';
fs.readFile(fileName, 'utf-8',function (err, data) {
if (err) res.send(err);
h=md2html.toHTML(data);
console.log(h);
res.render('blog',{h:h});
});
});
blog.ejs:
<html>
<head>
<title>lla</title>
<meta charset='utf-8'>
</head>
<body>
<%=h%>
</body>
<html>