Skip to content

Instantly share code, notes, and snippets.

@polm
Created August 22, 2013 23:41
Show Gist options
  • Save polm/6314057 to your computer and use it in GitHub Desktop.
Save polm/6314057 to your computer and use it in GitHub Desktop.
Quick start of a static blog in Coffeescript.
#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)
<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>
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