Skip to content

Commit

Permalink
build the nav with handlebars instead of js; add content.lite.json to…
Browse files Browse the repository at this point in the history
… the mix.
  • Loading branch information
zeke committed Oct 3, 2014
1 parent 6b27d57 commit b3a4d5e
Show file tree
Hide file tree
Showing 7 changed files with 772 additions and 62 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ triggers `npm run build`, which does the following:
1. Parses [HTML Frontmatter](#html-frontmatter) from the markdown files
1. Converts markdown to HTML
1. Writes [content.json](/content.json) with Base64-encoded markdown contents AND HTML contents
1. Writes [views/partials/nav.hbs](/views/partials/nav.hbs)
1. Writes [content.lite.json](/content.lite.json) with the same thing minus file contents.

The copied and generated files are [ignored](/.gitignore) for two reasons:

Expand Down
1 change: 0 additions & 1 deletion bin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ cp -r node_modules/npm/doc/files content/
cp -r node_modules/npm/doc/misc content/

./bin/tree.js
./bin/nav.js
43 changes: 0 additions & 43 deletions bin/nav.js

This file was deleted.

30 changes: 23 additions & 7 deletions bin/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var pluck = _.pluck
var merge = _.merge
var fm = require("html-frontmatter")
var contentFile = path.resolve(__dirname, "../content.json")
var liteFile = path.resolve(__dirname, "../content.lite.json")
var content = {
sections: [],
pages: []
Expand Down Expand Up @@ -84,22 +85,37 @@ emitter.on("end",function(){

var sections = compact(uniq(pluck(content.pages, 'section'))).sort()

content.sections = sections.map(function(section) {
content.sections = sections.map(function(id) {
var section = {
id: id,
title: id
}

// Look for a page named "index" in this section
var indexPage = _.find(content.pages, function(page) {
return path.basename(page.href) === "index" && page.section === section
return path.basename(page.href) === "index" && page.section === section.id
})

return {
id: section,
href: "/" + section,
title: (indexPage ? indexPage.title : section),
hasIndexPage: !!indexPage
// Inherit title and href from index page
if (indexPage) {
section.title = indexPage.title
section.href = indexPage.href
}

return section
})

fs.writeFileSync(contentFile, JSON.stringify(content, null, 2))
console.log("Wrote %s", path.relative(process.cwd(), contentFile))

var lite = merge({}, content)
lite.pages = lite.pages.map(function(page){
delete page.content
return page
})

fs.writeFileSync(liteFile, JSON.stringify(lite, null, 2))
console.log("Wrote %s", path.relative(process.cwd(), liteFile))


})
Loading

0 comments on commit b3a4d5e

Please sign in to comment.