-
Notifications
You must be signed in to change notification settings - Fork 884
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |