-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocpad.coffee
More file actions
255 lines (200 loc) · 7.64 KB
/
docpad.coffee
File metadata and controls
255 lines (200 loc) · 7.64 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
htmlToText = require('html-to-text')
# The DocPad Configuration File
# It is simply a CoffeeScript Object which is parsed by CSON
docpadConfig = {
# =================================
# Server configuration
port: 9000
# =================================
# Template Data
# These are variables that will be accessible via our templates
# To access one of these within our templates, refer to the FAQ: https://github.com/bevry/docpad/wiki/FAQ
templateData:
# Specify some site properties
site:
# The production url of our website
url: "https://www.univunix.com"
# The default title of our website
title: "UnivUnix"
titleComplement: "El portal unificado de Unix y Linux."
# Site keywords
keywords: [
"linux",
"noticias",
"tutoriales",
"programación",
"informática"
]
# The website description (for SEO)
description: """
Una web donde te pondremos al día en la información que rodea a Linux y derivados de Unix: noticias, tutoriales y software variado e interesante.
"""
# Styles
styles: [
"/styles/bootstrap-min.css"
]
# Scripts
scripts: [
"/scripts/app-min.js"
]
# -----------------------------
# Helper Functions
# Get the prepared site/document title
# Often we would like to specify particular formatting to our page's title
# we can apply that formatting here
getPreparedTitle: ->
# if we have a document title, then we should use that and suffix the site's title onto it
if @document.title
"#{@document.title} | #{@site.title}"
# if our document does not have it's own title, then we should just use the site's title
else
"#{@site.title} | #{@site.titleComplement}"
# Get the prepared site/document description
getPreparedDescription: ->
#if we have a document description, then we should use that, otherwise use the site's description
if @document.isCategoryPage or @document.isAuthorPage or not @document.title?
@site.description
else
@getPostExtract(String(@document.contentRenderedWithoutLayouts))
# Get the prepared site/document keywords
getPreparedKeywords: ->
# Merge the document keywords with the site keywords
@site.keywords.concat(@document.keywords or []).join(', ')
#--------------------------------
# Custom functions
getUrl: (url) ->
@site.url+url
getPostExtract: (content) ->
i = content.search('</p>')
if i >= 0
htmlToText.fromString content[0..i+3]
else
htmlToText.fromString content
formatURL: (url) ->
url.replace(/\s/g, "%20")
isPageCategory: (categories, indexTitle) ->
if categories? and indexTitle?
for cat in categories
if indexTitle.toLowerCase() == cat
return true
return false
# =================================
# Collections
# These are special collections that our website makes available to us
collections:
# Main collections
# ---------------------------------------
pages: ->
@getCollection('documents').findAllLive({isPage: true, isPagedAuto: $ne: true}, [pageOrder:1,title:1])
categoryPages: ->
@getCollection('documents').findAllLive({isCategoryPage: true, isPagedAuto: $ne: true}, [categoryOrder:1, title: 1])
authorPages: ->
@getCollection('documents').findAllLive({isAuthorPage: true, isPagedAuto: $ne: true}, [authorOrder:1, title: 1])
posts: ->
@getCollection('documents').findAllLive({categories:$exists:true}, [date:-1])
# Author collections
# ---------------------------------------
aglezabad: ->
@getCollection('posts').findAllLive({authors:$has:'Aglezabad'}, [date:-1])
ferthedems: ->
@getCollection('posts').findAllLive({authors:$has:'Ferthedems'}, [date:-1])
kennynnek: ->
@getCollection('posts').findAllLive({authors:$has:'Kennynnek'}, [date:-1])
# Category collections
# ---------------------------------------
arch: ->
@getCollection('posts').findAllLive({categories:$has:'arch'}, [date:-1])
debian: ->
@getCollection('posts').findAllLive({categories:$has:'debian'}, [date:-1])
fedora: ->
@getCollection('posts').findAllLive({categories:$has:'fedora'}, [date:-1])
firefoxos: ->
@getCollection('posts').findAllLive({categories:$has:'firefoxos'}, [date:-1])
linux: ->
@getCollection('posts').findAllLive({categories:$has:'linux'}, [date:-1])
mageia: ->
@getCollection('posts').findAllLive({categories:$has:'mageia'}, [date:-1])
mint: ->
@getCollection('posts').findAllLive({categories:$has:'mint'}, [date:-1])
noticias: ->
@getCollection('posts').findAllLive({categories:$has:'noticias'}, [date:-1])
opensuse: ->
@getCollection('posts').findAllLive({categories:$has:'opensuse'}, [date:-1])
programacion: ->
@getCollection('posts').findAllLive({categories:$has:'programación'}, [date:-1])
sabayon: ->
@getCollection('posts').findAllLive({categories:$has:'sabayon'}, [date:-1])
tutoriales: ->
@getCollection('posts').findAllLive({categories:$has:'tutoriales'}, [date:-1])
ubuntu: ->
@getCollection('posts').findAllLive({categories:$has:'ubuntu'}, [date:-1])
# =================================
# Plugins
# =================================
# DocPad Events
# Here we can define handlers for events that DocPad fires
# You can find a full listing of events on the DocPad Wiki
events:
# 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
# Redirect any requests accessing one of our 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()
#Write After
#Used to minify our assets with grunt.
writeAfter: (opts,next) ->
safeps = require('safeps')
pathUtil = require('path')
docpad = @docpad
rootPath = docpad.getConfig().rootPath
gruntPath = pathUtil.join(rootPath, 'node_modules', '.bin', 'grunt')
command = [gruntPath]
safeps.spawn(command, {cwd:rootPath,output:true}, next)
@
# =====================================
# Enviroments: development, production.
# Use docpad -e <enviroment> to select.
env: "production"
hostname: "localhost"
plugins:
livereload:
enabled: false
moment:
formats: [
{raw: 'date', format: 'YYYY-MM-DD', formatted: 'computerDate'}
{raw: 'date', format: 'DD/MM/YYYY', formatted: 'humanDate'}
{raw: 'date', format: 'ddd, DD MMM YYYY HH:mm:ss ZZ', formatted: 'rfcDate'}
]
sitemap:
cachetime: 600000
changefreq: 'weekly'
priority: 0.5
thumbnails:
imageMagick: true
targets:
'postMain': (img,args) ->
return img
.gravity('Center')
.resize(700)
.crop(700, 440)
'postMini': (img, args) ->
return img
.gravity('Center')
.resize(250,250)
.crop(250,250)
}
# Export our DocPad Configuration
module.exports = docpadConfig