You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
756 B
JavaScript
37 lines
756 B
JavaScript
9 years ago
|
'use strict'
|
||
|
|
||
|
var Handlebars = require('handlebars')
|
||
|
var Remarkable = require('remarkable')
|
||
|
var fs = require('fs')
|
||
|
|
||
|
var md = new Remarkable('full', {
|
||
|
html: true,
|
||
|
linkify: true,
|
||
|
typographer: true
|
||
|
})
|
||
|
|
||
|
Handlebars.registerHelper('md', function (src) {
|
||
|
var content = fs.readFileSync(src).toString()
|
||
|
|
||
|
return new Handlebars.SafeString(
|
||
|
md.render(content)
|
||
|
)
|
||
|
})
|
||
|
|
||
|
function compileTemplate(cb) {
|
||
|
fs.readFile('./src/index.hbs', function (err, content) {
|
||
|
if (err) return cb(err)
|
||
|
cb(null, Handlebars.compile(content.toString()))
|
||
|
})
|
||
|
}
|
||
|
|
||
|
compileTemplate(function (err, template) {
|
||
|
if (err) throw err
|
||
|
|
||
|
fs.writeFile('./public/index.html', template(), function (err) {
|
||
|
if (err) throw err
|
||
|
|
||
|
console.log('Wrote public/index.html')
|
||
|
})
|
||
|
})
|