-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocpad.js
118 lines (105 loc) · 2.67 KB
/
docpad.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
moment = require('moment')
cheerio = require('cheerio')
url = require('url')
docpadConfig = function(){
var categories = [
"ata",
"novosConhecimentos",
"geral"
]
return {
documentsPaths: ['documents', 'posts'],
filesPaths: ['assets'],
plugins: {
handlebars: {
helpers: {
getCollection: function(name){
return this.getCollection(name).toJSON()
},
dateAsText: function(date){
return moment(date).lang('pt').format('DD MMM YYYY')
},
getIdForDocument: function(document, docpad) {
var date, hostname, path
hostname = url.parse(docpad.site.url).hostname
date = document.date.toISOString().split('T')[0]
path = document.url
return "tag:" + hostname + "," + date + ":" + path
},
fixLinks: function(content, docpad) {
var $, baseUrl, regex
baseUrl = docpad.site.url
regex = /^(http|https|ftp|mailto):/
$ = cheerio.load(content)
$('img').each(function() {
var $img, src
$img = $(this)
src = $img.attr('src')
if (!regex.test(src)) {
return $img.attr('src', baseUrl + src)
}
})
$('a').each(function() {
var $a, href
$a = $(this)
href = $a.attr('href')
if (!regex.test(href)) {
return $a.attr('href', baseUrl + href)
}
})
return $.html()
},
feedDate: function(date){
return date.toISOString()
}
}
}
},
collections : function(){
var collections = {
posts : function(){
return this.getCollection("documents")
.setFilter('isPost', function(model){
var isIn = model.attributes.fullPath.substr((__dirname+'/src/').length)
return isIn.indexOf('posts') == 0
})
.on("add", function(model){
model.setMetaDefaults({layout: 'post'})
})
.setComparator(function(postA, postB){
var dateA = postA.toJSON().date
var dateB = postB.toJSON().date
return moment(dateB).unix() - moment(dateA).unix()
})
.live()
}
}
for(var i=0; i<categories.length; i++){
(function(){
var query = {category: categories[i]}
collections[categories[i]] = function(){
return this.getCollection("posts")
.findAllLive(query)
}
}())
}
return collections
}(),
templateData: {
site: {
title: "CaelUX"
}
},
environments: {
static: {
templateData: {
site: {
url: "http://leocwolter.github.io/caelux",
baseUrl: "/caelux"
}
}
}
}
}
}()
module.exports = docpadConfig