Skip to content

Commit

Permalink
We don’t need no base64. I blame the Atom editor for making me think …
Browse files Browse the repository at this point in the history
…my JSON was corrupt.
  • Loading branch information
zeke committed Oct 3, 2014
1 parent 7a4fcf6 commit 792d964
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ triggers `npm run build`, which does the following:
1. Reads the contents of each markdown file.
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 [content.lite.json](/content.lite.json) with the same thing minus file contents.
1. Writes [content.json](/content.json) with HTML content of each file included.
1. Writes [content.lite.json](/content.lite.json) with the same data minus the file content.

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

Expand All @@ -47,9 +47,6 @@ The [content.json](/content.json) file is served publicly at `/content.json`
with CORS support, allowing browsers on other domains to fetch all the npm
documentation and accompanying metadata with a single HTTP call.

The `content` property in each page object is Base64 encoded so it doesn't
break JSON.

## Deployment

```sh
Expand Down
3 changes: 0 additions & 3 deletions bin/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ emitter.on("file", function(filename,stat){
// Convert markdown to HTML
page.content = marked(page.content)

// Encode content so it can be saved as JSON
page.content = new Buffer(page.content).toString('base64')

// Clean up the filename
filename = filename
.replace(/.*\/content\//, "") // remove basepath
Expand Down
16 changes: 7 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ var harp = require("harp")
var path = require("path")
var cors = require("cors")
var find = require("lodash").find
var content = require(path.resolve(__dirname, "content.json"))
var contentLite = require(path.resolve(__dirname, "content.lite.json"))

var app = express()
app.set("view engine", "hbs")
app.set("port", (process.env.PORT || 5000))
Expand All @@ -12,24 +15,19 @@ app.use(harp.mount(__dirname + "/public"))
hbs.registerPartials(__dirname + "/views/partials")
hbs.registerHelper("equal", require("handlebars-helper-equal"))

// Fetch all the content, and convert Base64-encoded
// content back to regular strings
var content = require(path.resolve(__dirname, "content.json"))
content.pages = content.pages.map(function(page) {
page.content = (new Buffer(page.content, "base64")).toString()
return page
})

app.get("/content.json", cors(), function(req, res) {
res.json(content)
})

app.get("/content.lite.json", cors(), function(req, res) {
res.json(contentLite)
})

app.get("/*", function(req, res) {
var page = find(content.pages, function(page) {
return page.href === req.path
})

console.log(content)
res.render("page", {
page: page,
content: content
Expand Down

0 comments on commit 792d964

Please sign in to comment.