Created
August 22, 2013 23:41
-
-
Save polm/6314057 to your computer and use it in GitHub Desktop.
Quick start of a static blog in Coffeescript.
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
#Load deps | |
fs = require('fs') | |
jsdom = require('jsdom').jsdom | |
yaml = require('js-yaml') | |
trans = require('transparency') | |
marked = require('marked') | |
_ = require('underscore') | |
#Load yaml | |
#TODO Load files from directory - fs.readdir | |
# Then sort them by date fields | |
posts = require('./posts.yaml') | |
_.map(posts.posts, (p) -> p.content = marked(p.content)) | |
directives = posts: | |
content: | |
html: -> @content | |
#Load template | |
fs.readFile('./page.html', 'utf-8', (err, text) -> applyTemplate(text)) | |
#apply template | |
applyTemplate = (doc) -> | |
tmpl = jsdom(doc).getElementsByTagName('html')[0] | |
console.log(trans.render(tmpl, posts, directives).outerHTML) | |
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
<html> | |
<div id="posts"> | |
<div class="post"> | |
<h1 class="title">This is a post</h1> | |
<div class="content">These are words.</div> | |
</div> | |
</div> | |
</html> |
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
posts: | |
- title: yes | |
content: | | |
maybe yes, maybe no | |
Will you eat my pie? | |
- title: no | |
content: | | |
cake pie fish tuesday? | |
science **catfish** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment