-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocpad.coffee
More file actions
214 lines (189 loc) · 5.55 KB
/
docpad.coffee
File metadata and controls
214 lines (189 loc) · 5.55 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# DocPad Configuration File
# http://docpad.org/docs/config
environment = require('./environment.json')
mongoMembership = require('./auth/mongoMembership')
# Define the DocPad Configuration
docpadConfig = {
regenerateDelay: 1000
ignoreHiddenFiles: true
port: 9778
checkVersion: true
templateData:
site:
url: "http://univunix.com"
title: "UnivUnix"
description: """
El portal unificado de Unix, sus derivados y el software libre.
Ahora con temas mas allá del software.
"""
keywords: """
Unix, GNU, Linux, Mac, BSD, software, libre, electrónica, impresión, 3D
"""
# Helper functions
getDocumentTitle: ->
if @document.title
"#{@document.title} | #{@site.title}"
else
@site.title
getDocumentDescription: ->
@document.description or @site.description
getKeywords: ->
@site.keywords.concat(@document.keywords or []).join(', ')
formatURL: (url) ->
url
.replace(/\s/g, "%20")
.replace(/&/g, "&")
encodeTextToURI: (text) ->
encodeURIComponent(text)
getFullURL: (relativeURL) ->
@formatURL(@site.url + relativeURL)
collections:
articles: ->
@getCollection("documents").findAllLive({
relativeOutDirPath: /articles\/*/,
isPagedAuto: $ne: true
}, [{date: -1}]).on "add", (model) ->
model.setMetaDefaults({layout: "article"})
pages: ->
@getCollection("documents").findAllLive({
relativeOutDirPath: "pages",
isPagedAuto: $ne: true
}, [{date: -1}]).on "add", (model) ->
model.setMetaDefaults({layout:"page"})
categories: ->
@getCollection("documents").findAllLive({
relativeOutDirPath: "categories",
isPagedAuto: $ne: true
}, [{date: -1}]).on "add", (model) ->
model.setMetaDefaults({layout: "category",
isPaged: true,
pageSize: 8})
# CATEGORIES
guides: ->
@getCollection("articles").findAllLive({
relativeOutDirPath: /articles\/guides/
}, [{date: -1}])
#Environment configuration
localeCode: 'es'
environments:
development:
templateData:
site:
url: "http://localhost:9778"
hostname: 'localhost'
maxAge: false
production:
maxAge: false
hostname: 'univunix.com'
# Plugins configuration
plugins:
api:
cfgSrc: [
'api/dpaconfig.json'
]
authentication:
protectedUrls: ['/articles/guides/buenas-practicas-en-nginx-conf']
forceServerCreation: true
ensureAuthenticated: mongoMembership.ensureAuthenticated
findOrCreate: mongoMembership.findOrCreate
getUsers: mongoMembership.getUsers
strategies:
google:
settings:
clientID: environment.authentication.google.id
clientSecret: environment.authentication.google.secret
authParameters:
scope: [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email'
]
url:
auth: '/auth/google'
callback: '/auth/google/callback'
success: '/'
fail: '/login'
github:
settings:
clientID: environment.authentication.github.id
clientSecret: environment.authentication.github.secret
url:
auth: '/auth/github'
callback: '/auth/github/callback'
success: '/'
fail: '/login'
imagin:
imageMagick: true
targets:
'articleList': (img, args) ->
return img
.resize(698, 396, "^")
.gravity('Center')
.crop(698, 396)
'articleHeader': (img, args) ->
return img
.gravity('Center')
.crop(480, 52)
.blur(10, 5)
less:
referencesOthers: true
# http://lesscss.org/#using-less-configuration
lessOptions:
compress: true,
sourceMap:
sourceMapFileInline: true
marked:
gfm: true
tables: true
breaks: true
highlight: null
moment:
formats: [
{
raw: 'date',
format: 'YYYY-MM-DD',
formatted: 'pc'
},
{
raw: 'date',
format: 'DD/MM/YYYY',
formatted: 'human'
}
]
paged:
split: true,
prefix: 'page'
related:
parentCollectionName: 'articles'
rss:
default:
collection: 'articles'
#Event configuration
events:
docpadReady: ->
docpad = @docpad
mongoMembership.docpadReady docpad, environment
docpadDestroy: ->
docpad = @docpad
mongoMembership.docpadDestroy docpad
# Server Extend
# Used to add our own custom routes to the server before the docpad routes are added
serverExtend: (opts) ->
# Extract the server from the options
{server} = opts
docpad = @docpad
# As we are now running in an event,
# ensure we are using the latest copy of the docpad configuraiton
# and fetch our urls from it
latestConfig = docpad.getConfig()
oldUrls = latestConfig.templateData.site.oldUrls or []
newUrl = latestConfig.templateData.site.url
# sites oldUrls to the new site url
server.use (req,res,next) ->
if req.headers.host in oldUrls
res.redirect(newUrl+req.url, 301)
else
next()
mongoMembership.serverExtend opts
}
# Export the DocPad Configuration
module.exports = docpadConfig