-
Notifications
You must be signed in to change notification settings - Fork 18
/
docpad.coffee
executable file
·388 lines (321 loc) · 11.1 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
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# The DocPad Configuration File
# It is simply a CoffeeScript Object which is parsed by CSON
path = require('path')
docpadConfig = {
# =================================
# 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
prompts: false,
templateData:
# Specify some site properties
site:
# The production url of our website
# If not set, will default to the calculated site URL (e.g. http://localhost:9778)
url: "http://website.com"
# Here are some old site urls that you would like to redirect from
oldUrls: [
'www.website.com',
'website.herokuapp.com'
]
# The default title of our website
title: "SOOMLA Knowledge Base"
# The website description (for SEO)
description: """
Game programming framework for free to play mobile games. Easily develop: virtual economy, in-app purchase (IAP), levels, worlds, scores and social functions.
"""
# The website keywords (for SEO) separated by commas
keywords: """
game programming framework, virtual economy, in app purchase, gaming, indie developers
"""
# The website's styles
styles: [
'/styles/tocify.css'
'/styles/highlightcode.css'
'/styles/footer.css'
'/styles/knowledge.css'
]
# The website's scripts
scripts: [
'/scripts/jquery-ui-1-10-4-min.js',
'/vendor/log.js'
'/vendor/modernizr.js'
'/scripts/jquery-tocify-min.js'
'/scripts/knowledge-base.js'
]
topLevelNavItems: [
{
id: 'unity',
title: 'Unity',
link: '/unity'
}
{
id: 'cocos2dx',
title: 'Cocos2d-x',
link: '/cocos2dx'
}
{
id: 'ios',
title: 'iOS',
link: '/ios'
}
{
id: 'android',
title: 'Android',
link: '/android'
}
{
id: 'university',
title: 'University',
link: '/docs/university/videos'
}
{
id: 'download',
title: 'Download',
link: '/download'
}
]
soomlaModules: {
'unity': [
{
id: 'store',
title: 'Store'
}
{
id: 'profile',
title: 'Profile'
}
{
id: 'levelup',
title: 'LevelUp'
}
{
id: 'grow',
title: 'GROW'
}
],
'cocos2dx': [
{
id: 'store',
title: 'Store'
}
{
id: 'profile',
title: 'Profile'
}
{
id: 'levelup',
title: 'LevelUp'
}
{
id: 'grow',
title: 'GROW'
}
],
'ios': [
{
id: 'store',
title: 'Store'
}
{
id: 'profile',
title: 'Profile'
}
],
'android': [
{
id: 'store',
title: 'Store'
}
{
id: 'profile',
title: 'Profile'
}
]
}
# -----------------------------
# 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
# Get the prepared site/document description
getPreparedDescription: ->
# if we have a document description, then we should use that, otherwise use the site's description
@document.description or @site.description
# Get the prepared site/document keywords
getPreparedKeywords: ->
# Merge the document keywords with the site keywords
@site.keywords.concat(@document.keywords or []).join(', ')
getGruntedStyles: ->
_ = require 'underscore'
styles = []
gruntConfig = require('./grunt-config.json')
_.each gruntConfig, (value, key) ->
styles = styles.concat _.flatten _.pluck value, 'dest'
styles = _.filter styles, (value) ->
return value.indexOf('.min.css') > -1
_.map styles, (value) ->
return value.replace 'out', ''
getGruntedScripts: ->
_ = require 'underscore'
scripts = []
gruntConfig = require('./grunt-config.json')
_.each gruntConfig, (value, key) ->
scripts = scripts.concat _.flatten _.pluck value, 'dest'
scripts = _.filter scripts, (value) ->
return value.indexOf('.min.js') > -1
_.map scripts, (value) ->
return value.replace 'out', ''
# =================================
# Collections
# Here we define our custom collections
# What we do is we use findAllLive to find a subset of documents from the parent collection
# creating a live collection out of it
# A live collection is a collection that constantly stays up to date
# You can learn more about live collections and querying via
# http://bevry.me/queryengine/guide
# That contains all the documents that will be going to the out path posts
collections:
downloads: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('docs','downloads')},[position:1])
platforms: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('docs','platforms')},[position:1])
soomla: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('docs','soomla')},[position:1])
university: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('docs','university')},[position:1])
ios_store: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('ios','store')},[position:1])
ios_profile: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('ios','profile')},[position:1])
ios_levelup: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('ios','levelup')},[position:1])
android_store: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('android','store')},[position:1])
android_profile: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('android','profile')},[position:1])
android_levelup: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('android','levelup')},[position:1])
cocos2dx_store: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('cocos2dx','cpp','store')},[position:1])
cocos2dx_profile: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('cocos2dx','cpp','profile')},[position:1])
cocos2dx_levelup: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('cocos2dx','cpp','levelup')},[position:1])
cocos2dx_grow: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('cocos2dx','cpp','grow')},[position:1])
cocos2djs_store: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('cocos2dx','js','store')},[position:1])
cocos2djs_profile: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('cocos2dx','js','profile')},[position:1])
cocos2djs_levelup: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('cocos2dx','js','levelup')},[position:1])
cocos2djs_grow: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('cocos2dx','js','grow')},[position:1])
unity_store: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('unity','store')},[position:1])
unity_profile: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('unity','profile')},[position:1])
unity_levelup: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('unity','levelup')},[position:1])
unity_grow: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('unity','grow')},[position:1])
soomla_levelup: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('docs','soomla', 'levelup')},[position:1])
soomla_store: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('docs','soomla', 'store')},[position:1])
soomla_highway: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('docs','soomla', 'highway')},[position:1])
soomla_storefront: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('docs','soomla', 'storefront')},[position:1])
university_articles: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('docs','university', 'articles')},[position:1])
university_datacommunity: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('docs','university', 'datacommunity')},[position:1])
university_realworldexamples: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('docs','university', 'realworldexamples')},[position:1])
university_videos: ->
@getCollection('documents').findAllLive({relativeOutDirPath: path.join('docs','university', 'videos')},[position:1])
# =================================
# Environments
# DocPad's default environment is the production environment
# The development environment, actually extends from the production environment
# The following overrides our production url in our development environment with false
# This allows DocPad's to use it's own calculated site URL instead, due to the falsey value
# This allows <%- @site.url %> in our template data to work correctly, regardless what environment we are in
environments:
static:
maxAge: false
development:
maxAge: false
templateData:
site:
url: false
watchOptions:
preferredMethods: ['watchFile','watch']
# watchOptions:
# catchupDelay: 0
regenerateDelay: 0
# =================================
# 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
#
# Gur: commented out because it conflicts with the default behavior of the
# docpad grunt plugin, which registers to this hook by default
#
# writeAfter: (opts,next) ->
#
# # Prepare
# safeps = require('safeps')
# docpad = @docpad
# rootPath = docpad.getConfig().rootPath
# gruntPath = path.join('node_modules', 'docpad-plugin-grunt', 'node_modules', '.bin', 'grunt')
#
# command = [gruntPath, 'default']
#
# # Execute
# safeps.spawn(command, {cwd:rootPath,output:true}, next)
#
# # Chain
# @
plugins:
grunt:
environments:
development:
enabled: false
ignoreincludes:
ignoredExtensions: ['inc', 'min', 'map']
livereload:
enabled: false
}
# Export our DocPad Configuration
module.exports = docpadConfig