Skip to content

Commit

Permalink
build per argv
Browse files Browse the repository at this point in the history
  • Loading branch information
Jessica Lord committed Oct 13, 2014
1 parent de2c3d9 commit 1cbe3d9
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions guide/buildpages.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ var glob = require('glob')

var layout = fs.readFileSync(__dirname + '/layout.hbs').toString()
var thefiles = []
var lang = process.argv[2]

// I can probably use glob better to avoid
// finding the right files within the files
glob("*.html", {cwd: __dirname + '/raw-content'}, function (err, files) {
var rawFiles = __dirname + (lang ? '/raw-content-/' + lang : '/raw-content/')
var builtContent = __dirname + (lang ? '/chalenges-' + lang : '/challenges')
console.log(rawFiles, builtContent)

glob("*.html", {cwd: rawFiles}, function (err, files) {
thefiles = files
if (err) return console.log(err)
// var matches = files.map(function(file) {
Expand All @@ -23,15 +28,15 @@ function buildPage(files) {
// shouldn't have to do this if my
// mapping were correct
if (!file) return
var content = {
header: buildHeader(file),
footer: buildFooter(file),
body: fs.readFileSync(__dirname + '/raw-content/' + file).toString()
var content = {
header: buildHeader(file),
footer: buildFooter(file),
body: fs.readFileSync(rawFiles + file).toString()
}
var shortname = makeShortname(file)
var template = Handlebars.compile(layout)
var final = template(content)
fs.writeFileSync(__dirname + '/challenges/' + shortname + 'html', final)
fs.writeFileSync(builtContent + shortname + 'html', final)
})
// hard coded right now because, reasons
console.log("Built!")
Expand Down Expand Up @@ -75,6 +80,7 @@ function grammarize(name) {
function buildFooter(file) {
var num = file.split('/').pop().split('_')[0]
var data = getPrevious(num)
data.lang = lang ? '-' + lang : ''
var source = fs.readFileSync(__dirname + '/partials/footer.html').toString()
var template = Handlebars.compile(source)
// console.log(data)
Expand Down Expand Up @@ -107,7 +113,6 @@ function getPrevious(num) {
nexturl = file.replace(getridof, '')
}
})
return {prename: prename, preurl: preurl,
return {prename: prename, preurl: preurl,
nextname: nextname, nexturl: nexturl}
}

0 comments on commit 1cbe3d9

Please sign in to comment.