summary refs log tree commit diff stats
path: root/src/modules/posts.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/posts.js')
-rw-r--r--src/modules/posts.js15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/modules/posts.js b/src/modules/posts.js
index 011292b..cba2372 100644
--- a/src/modules/posts.js
+++ b/src/modules/posts.js
@@ -3,12 +3,20 @@
 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) {
     yield [String(k).toLowerCase(), v]
@@ -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 @@ function toTags (posts) {
 module.exports = {
   get,
   getFolder,
-  toTags
+  toTags,
+  render
 }