-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.coffee
73 lines (58 loc) · 2.04 KB
/
app.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#--------------------------------------------------------
# Requirements
#--------------------------------------------------------
express = require 'express'
poet = require 'poet'
markdown = require("node-markdown").Markdown
fs = require 'fs'
path = require 'path'
jade = require 'jade'
frontmatter = require 'front-matter'
#--------------------------------------------------------
# Express config
#--------------------------------------------------------
app = express()
app.set 'views', path.join(__dirname, "views")
app.set 'view engine', 'jade'
app.use express.static(__dirname + '/public')
app.locals.pretty = true
app.locals.basedir = path.join(__dirname, 'views')
app.listen 3000, ->
console.log "App running at http://localhost:3000"
#--------------------------------------------------------
# Poet Config
#--------------------------------------------------------
poet = poet app,
posts: "./content/posts/"
postsPerPage: 5
metaFormat: "json"
routes:
'/blog/:post': 'blog/post'
poet.init()
#--------------------------------------------------------
# Routes
#--------------------------------------------------------
# Blog Homepage
app.get '/blog', (req, res)->
res.render "blog/index"
# Markdown examples - Try '/markdown', '/markdown/one', 'markdown/two'
app.get '/markdown/:page?', (req, res)->
page = req.params.page || "index"
filePath = path.join __dirname, "content/markdown/#{page}.md"
fs.readFile filePath, 'utf-8', (err, data) ->
if err
res.status(404).send('Not Found 404')
else
res.render "templates/markdown-template",
meta: frontmatter(data).attributes
markdownContent: markdown(frontmatter(data).body)
# Pages - using yaml frontmatter
app.get '/:page?', (req, res)->
page = req.params.page || "index"
filePath = path.join __dirname, "views/pages/#{page}.jade"
fs.readFile filePath, 'utf8', (err, data) ->
if err
res.status(404).send('Not Found 404')
else
res.render "pages/#{page}",
meta: frontmatter(data).attributes