forked from shama/dontkry.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docpad.coffee
61 lines (53 loc) · 1.87 KB
/
docpad.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
module.exports = ->
path = require('path')
_s = require('underscore.string')
cheerio = require('cheerio')
config =
outPath: 'dist'
templateData:
site:
url: 'http://dontkry.com'
title: 'dontkry.com'
description: ''
keywords: ''
getPreparedTitle: ->
if @document.title
@document.title + ' | ' + @site.title
else
@site.title
# convert h2 headers to anchor links
headersToLinks: ->
if @document.extension is 'md'
$ = cheerio.load(@content)
$('h2').each (h2) ->
id = $(@).attr('id')
a = $('<a/>').attr(href:'#'+id,name:id).html($(@).html())
$(@).empty().append(a)
return $.html()
printItems: (items) ->
out = ''
i = 0
while i < items.length
item = items[i]
unless item.title
item.title = item.slug
item.url = 'http://shama.github.io/' + item.slug
url = item.url or 'http://' + item.slug + '.com'
out += '<li><a href=\'' + url + '\' target=\'_blank\'>'
out += '<img src=\'images/projects/' + item.slug + '.png\' alt=\'' + item.title + '\' />'
out += '<div>' + item.title + '</div></a>'
out += '</li>'
i++
out
# edit links to gh
ghedit: ->
filename = @document.relativeDirPath + '/' + @document.filename
return '<a href="https://github.com/shama/dontkry.com/edit/master/src/documents/' + filename + '" target="_blank">edit this page</a>'
ignorePaths: [path.join(__dirname, 'src', 'public', 'scss'), path.join(__dirname, 'src', 'public', 'js')]
collections:
posts: ->
@getCollection('html').findAllLive
relativeOutDirPath: $in: ['posts/code', 'posts/games'], [date: -1]
plugins:
rss:
collection: 'posts'