-
Notifications
You must be signed in to change notification settings - Fork 1
/
docpad.coffee
118 lines (90 loc) · 3.55 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
docpadConfig = {
growl: false # turns off system notifications
outPath: 'out'
templateData:
site:
url: "http://www.krijgerzeefdruk.nl" + (@subDir ? '')
oldUrls: [
]
# The default title of our website
title: "Krijger Zeefdruk"
# The website description (for SEO)
description: """
Krijger zeefdruk is een ambachtelijke zeefdrukkerij in Amsterdam Noord.
Wij bieden hoge kwaliteit en ruime mogelijkheden met gebruik van vele materialen en inkten.
"""
# The website keywords (for SEO) separated by commas
keywords: """
zeefdruk, zeefdrukkerij, amsterdam, bedrukking, drukwerk, glas, plastic, kunst, speciaal, speciale, inkt, visitekaartjes
"""
# The website author's name
author: "Quinten Krijger"
# The website author's email
email: "qkrijger@gmail.com"
getUrl: (document) ->
baseUrl = @subDir ? ''
if typeof document is "string"
baseUrl + document
else
baseUrl + (document.url or document.get?('url'))
getUrlForDocumentWithName: (name) ->
@getUrl(@findDocumentWithName(name))
getUrls: (documents) ->
(@getUrl(document) for document in documents)
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(', ')
findDocumentsWithNames: (documentNames) ->
comparator = (doc1, doc2) ->
index1 = documentNames.indexOf(doc1.toJSON().name)
index2 = documentNames.indexOf(doc2.toJSON().name)
if index1 < index2 then -1 else if index1 is index2 then 0 else 1
@getDatabase().findAllLive({name: $in: documentNames}, comparator )
findDocumentWithName: (documentName) ->
documents = @getDatabase().findAllLive({name: documentName})
# if documents.length isnt 1
# console.warn('Found ' + documents.length + ' documents with name "' + documentName '", where 1 was expected.')
documents.toJSON()[0]
plugins:
sass:
compass: true
collections: {}
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()
environments:
prodSim:
outPath: 'out'
templateData:
subDir: ''
}
# Export our DocPad Configuration
module.exports = docpadConfig