Skip to content

Commit

Permalink
Update build pages script
Browse files Browse the repository at this point in the history
  • Loading branch information
jlord committed Mar 19, 2017
1 parent 28b8d8a commit c77ee26
Showing 1 changed file with 31 additions and 59 deletions.
90 changes: 31 additions & 59 deletions scripts/buildpage.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,47 @@
#!/usr/bin/env node

var glob = require('glob')
var fs = require('fs')
var marked = require('marked')
var hbs = require('handlebars')
var mkdirp = require('mkdirp')
var glob = require('glob')
var path = require('path')
var cpr = require('cpr')
var mustache = require('mustache')

cpr('./demos', './site/demos', function(err, files) {
glob('docs/*.md', function (err, files) {
if (err) return console.log(err)
cpr('./js', './site/js', function(err, files) {
if (err) return console.log(err)
files.forEach(function (file) {
var filename = file.replace('docs/', '').split('.md')[0]
var md = fs.readFileSync(file).toString()
var html = changeExtensions(marked(md), filename)
applyTemplate(html, filename)
})
})

fs.readFile('readme.md', function(err, file) {
if (err) return console.log(err)
var name = "index"
var content = file.toString()
var html = changeExtensions(marked(content))
applyTemplate(html, name)
})

glob("docs/*.md", function (err, files) {
if (err) return console.log(err)
var filenames = files.map(function(name) {
return path.basename(name)
})
filenames.forEach(function (file) {
var name = file.split('.md')[0]
var filePath = "./docs/"
var content = fs.readFileSync(filePath + file).toString()
var html = changeExtensions(marked(content))
applyTemplate(html, name)
})
})
// Turn .md extension links within the files into .html
function changeExtensions (html, name) {
if (name === 'index') {
html = html.replace('/\./\.\/', '')
}
// var re = /.md$/
var newHtml = html.replace(/\.md/g, '.html')
return newHtml
}

function applyTemplate(html, name) {
function applyTemplate (html, name) {
var content = {content: html, name: name}
if (name === "index") {
content.rootstyle = "."
content.rootdoc = "docs"
content.rootdemo = "."
if (name === 'index') {
content.rootstyle = '.'
content.rootdoc = 'docs'
content.rootdemo = '.'
} else {
content.rootstyle = ".."
content.rootdoc = "."
content.rootdemo = ".."
content.rootstyle = '..'
content.rootdoc = '.'
content.rootdemo = '..'
}
var file = "template.hbs"
var rawTemplate = fs.readFileSync(file).toString()
var template = hbs.compile(rawTemplate)
var page = template(content)
var rawTemplate = fs.readFileSync('./scripts/template.hbs').toString()
var page = mustache.render(rawTemplate, content)
writeFile(page, name)
}

function writeFile(page, name) {
if (name === "index") {
return fs.writeFileSync('./site/' + name + '.html' , page)
}
mkdirp('./site/docs', function (err) {
if (err) return console.error(err)
fs.writeFileSync('./site/docs/' + name + '.html' , page)
})
}

function changeExtensions(html, name) {
if (name === "index") {
html = html.replace('/\./\.\/', '')
}
var re = /.md$/
var newHtml = html.replace(/\.md/g, '.html')
return newHtml
function writeFile (page, name) {
if (name === 'index') {
fs.writeFileSync(path.join(name + '.html'), page)
} else fs.writeFileSync(path.join('docs/', name + '.html'), page)
}

0 comments on commit c77ee26

Please sign in to comment.