all repos — archive/homestead @ 33171a749162685e42650f82041cd2af0136718d

My future indieweb platform

feat(posts): render posts as markdown

Alan Pearce
commit

33171a749162685e42650f82041cd2af0136718d

parent

1a36d4dc311a86246fe854da888af01f8195368e

1 file changed, 14 insertions(+), 1 deletion(-)

changed files
M src/modules/posts.jssrc/modules/posts.js
@@ -3,11 +3,19 @@
const fs = require('fs') const path = require('path') const matter = require('gray-matter') +const Markdown = require('markdown-it') const grayMatterOptions = { lang: 'toml', delims: '+++' } + +const markdownOptions = { + html: true, + typographer: true +} + +const markdown = new Markdown(markdownOptions) function* lowercaseKeys (iterator) { for (let [k, v] of iterator) {
@@ -28,6 +36,10 @@ function getTitle (file) {
return path.basename(file.path, path.extname(file.path)) } +function render (post) { + return markdown.render(post.content) +} + function get (filename) { const fileMatter = matter.read(filename, grayMatterOptions) fileMatter.basename = getTitle(fileMatter)
@@ -59,5 +71,6 @@
module.exports = { get, getFolder, - toTags + toTags, + render }