Skip to content
Browse files

documents render

  • Loading branch information...
1 parent 9e41226 commit 800f448649427ec53508737e2798d5e814c92528 @substack committed Dec 24, 2012
Showing with 37 additions and 3 deletions.
  1. +1 −3 static/index.html
  2. +36 −0 static/main.js
View
4 static/index.html
@@ -1,7 +1,5 @@
<html>
- <head>
- </head>
<body>
- blog entries...
+ <script src="bundle.js"></script>
</body>
</html>
View
36 static/main.js
@@ -0,0 +1,36 @@
+var http = require('http');
+var JSONStream = require('JSONStream');
+var through = require('through');
+
+http.get({ path : '/blog.json?inline=html' }, function (res) {
+ var parser = JSONStream.parse([ true ]);
+ parser.pipe(through(function (doc) {
+ var div = createArticle(doc);
+ document.body.appendChild(div);
+ }));
+ res.pipe(parser);
+});
+
+function createArticle (doc) {
+ var div = document.createElement('div');
+
+ var title = document.createElement('div');
+ var anchor = document.createElement('a');
+ var name = doc.title.replace(/[^A-Za-z0-9]+/g,'_');
+ anchor.setAttribute('name', name);
+ anchor.setAttribute('href', '#' + name);
+ anchor.textContent = doc.title;
+ title.appendChild(anchor);
+ div.appendChild(title);
+
+ var date = document.createElement('div');
+ date.textContent = doc.date;
+ div.appendChild(date);
+
+ var body = document.createElement('div');
+ div.appendChild(body);
+
+ body.innerHTML = doc.body;
+
+ return div;
+}

0 comments on commit 800f448

Please sign in to comment.
Something went wrong with that request. Please try again.