-
Notifications
You must be signed in to change notification settings - Fork 83
/
docpad.coffee
executable file
·153 lines (113 loc) · 4.16 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
# The DocPad Configuration File
# It is simply a CoffeeScript Object which is parsed by CSON
docpadConfig = {
sourcePaths : ['./server']
outPath: './out'
# test production env
# env: 'production'
plugins:
ghpages:
deployRemote: 'origin'
deployBranch: 'gh-pages'
serve:
listenOptions:
port: 9778
host: 'localhost'
# =================================
# 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://fomantic-ui.com"
# Here are some old site urls that you would like to redirect from
oldUrls: [],
version: "2.9.3",
branch: "master",
# The default title of our website
title: "Fomantic-UI"
# The website description (for SEO)
description: """
Fomantic-UI - The official community fork of Semantic-UI
"""
# The website keywords (for SEO) separated by commas
keywords: """
html5, ui, library, framework, javascript, css, fork, official
"""
# -----------------------------
# 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
getDirPath: ->
@document.dirPath
getVersion: ->
@site.version
getBranch: ->
@site.branch
getZip: ->
if @site.version
"https://github.com/fomantic/Fomantic-UI/archive/" + @site.version + ".zip"
else
"https://github.com/fomantic/Fomantic-UI/archive/master.zip"
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} Docs"
# if our document does not have it's own title, then we should just use the site's title
else
@site.title
getPage: (collection, id) ->
for item, index in collection
selectedIndex = (index + 1) if item.id is id
selectedIndex
pageCount: (collection) ->
for item, index in collection
itemCount = index + 1
itemCount
getPageCollection: (collection, id, delta = 2) ->
for item, index in collection
selectedIndex = index if item.id is id
lastIndex = index
# determine page count before and after
bottomCount = if (selectedIndex - delta >= 0) then delta else (selectedIndex)
topCount = if (selectedIndex + delta <= lastIndex) then delta else (lastIndex - selectedIndex)
bottomDelta = (delta * 2 - topCount)
topDelta = (delta * 2 - bottomCount)
bottomIndex = if (selectedIndex - bottomDelta >= 0) then (selectedIndex - bottomDelta) else 0
topIndex = if (selectedIndex + topDelta <= lastIndex) then (selectedIndex + topDelta) else lastIndex
result = collection[bottomIndex..topIndex]
result
# 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(', ')
# =================================
# Custom Collections
collections:
uiElements: ->
@getCollection("documents").findAllLive({type: $in: ['UI Element']}, [{title: 1}])
uiCollections: ->
@getCollection("documents").findAllLive({type: $in: ['UI Collection']}, [{title: 1}])
uiViews: ->
@getCollection("documents").findAllLive({type: $in: ['UI View']}, [{title: 1}])
uiModules: ->
@getCollection("documents").findAllLive({type: $in: ['UI Module', 'UI Behavior']}, [{title: 1}])
# =================================
# 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:
events:
extendCollections: (opts) ->
@docpad.getCollection('files').on('add', (document) ->
document.setMetaDefaults(standalone:true))
}
# Export our DocPad Configuration
module.exports = docpadConfig