This repository has been archived by the owner on Jul 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdocpad.coffee
303 lines (245 loc) · 9.46 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
require('./helpers/objectsPrototypes.js');
gulpFunctions = require('./gulpFunctions.js');
validate = require('./helpers/validateMetadata.js')
config = require('./chewieConfig');
customization = require('./helpers/customization.js')(config);
#variables used many times in docpad.coffee that can be stored like this
deployment = {
functions:
writeAfter: [gulpFunctions.replaceApiReferences]
generateAfter: [gulpFunctions.fixTables, gulpFunctions.fixLinks, gulpFunctions.serviceLatest]
docpadReady: [validate]
styles: ["/styles/devportal-yaas.css"]
scripts: ["/scripts/devportal-yaas.min.js"]
headScripts: ["/scripts/devportal-yaas-head.min.js"]
}
docpadConfig = {
pluginsPaths: [ # default
'node_modules'
'plugins'
]
# =================================
# Template Data
# These are variables that will be accessible via our templates
templateData:
watchOptions: preferredMethods: ['watchFile','watch']
# Specify some site properties
site:
# Scripts
headScripts: [
"/bower_components/jquery/dist/jquery.min.js"
"/bower_components/bootstrap/dist/js/bootstrap.min.js"
"/bower_components/select2/select2.min.js"
"/bower_components/lscache/lscache.min.js"
"/scripts/custom/polyfills.js"
"/bower_components/kjur-jsrsasign/jws-3.3.js"
"/build/plugins/embed-hash-persistence.js"
"/scripts/custom/jquery-custom-animations.js"
"/scripts/custom/jquery-custom-prototypes.js"
]
navPersonalizationScripts: [
"/bower_components/underscore/underscore-min.js"
#"/scripts/custom/listing.js"
]
scripts: [
"/scripts/general/opt-in-features.js"
"/scripts/general/modernizr.js"
"/scripts/general/offcanvas.js"
"/scripts/general/backtop.js"
"/scripts/general/scrollspy.js"
"/scripts/general/remember_location.js"
"/scripts/general/ZeroClipboard-min.js"
"/scripts/general/expand-collapse.js"
"/scripts/general/code-block.js"
"/scripts/general/img-click-modal.js"
"/scripts/general/apiref.js"
"/scripts/general/left-nav-indicators.js"
"/scripts/general/replace-svg-images-with-inline-svg.js"
"/scripts/general/api-filter.js"
"/scripts/general/api-console.js"
"/scripts/general/ignore-scrolling.js"
"/scripts/general/add-margin-to-content-with-sticky-header.js"
"/scripts/general/load-tutorial.js"
"/scripts/general/mermaid.js"
"/scripts/general/startMermaid.js"
]
styles: [
"/styles/main.css"
"/styles/7-components/super-nav.css"
]
# The production url of our website
url: if process.env.DEPLOY then config.docuUrl else 'http://127.0.0.1:9778'
yaasUrl: "https://www.yaas.io"
home: ""
googleAnalytics: () -> ''
# The default title of our website
title: "Simple API Docs Skeleton"
# The website description (for SEO)
description: "Skeleton for your API Documentation"
# The website keywords (for SEO) separated by commas
keywords: ""
# The website author's name
author: ""
# -----------------------------
# Helper Functions
# helper used in several placeholders to build navigation links
# out of service's names or titles. Removes all spaces and special chars
getSiteUrl: ->
@site.url
getYaasUrl: ->
@site.yaasUrl
getHomeUrl: ->
@site.home
getTrimmedName: (name) ->
name.replace(/([^\w-])/g,"")
#gets a docpad object's relativeDirPath on input
getVersion: (path, allowedArrayLength) ->
#need to cut out the version out of the path
fullPathArray = path.split('/')
# need to make sure nobody messed up with their
# docu structure and it is docu/files/flet.html.md
if !(fullPathArray.length > allowedArrayLength)
fullPathArray[fullPathArray.length-1]
else "Version name on last position in the path "+path+" is not char + one or two digits"
getVersionDigit: (path, allowedArrayLength) ->
fullPathArray = path.split('/')
# need to make sure nobody messed up with their
# docu structure and it is docu/files/flet.html.md
if !(fullPathArray.length > allowedArrayLength)
fullVersion = fullPathArray[fullPathArray.length-1]
#need to get a version number and be ready for 2 digits versions
if fullVersion.length is 3
fullVersion.slice(1,3)
else if fullVersion.length is 2
fullVersion.slice(1)
else "Version name on last position in the path "+path+" is not char + one or two digits"
# 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(', ')
trimTo140Char: (content) ->
if content.length > 140
content.substr(0, 140) + '...'
else
content
removeRedundantMeta: (content) ->
findMeta = content.indexOf('---', 3)
if(findMeta == -1) # if no meta - probably will never happen
return content
return '\n' + content.substr(findMeta + 3) + '\n' # add because indexOf returns index of first character, we need to trim to last
# added \n at the begining and end so it will render properly
getGeneralNavItems: customization.getGeneralNavItems
getCustomLandingPage: customization.getCustomLandingPage
# =================================
# Collections
# These are special collections that our website makes available to us
collections:
# Get all rn sorted by order meta
releaseNotes: ->
@getCollection("documents")
.findAllLive({url:$startsWith: "/rn"},[filename:-1])
# Get all rn sorted by order meta
apiconsoles: ->
@getCollection("documents")
.findAllLive(
{url:{$startsWith: "/apiconsoles"},
filename: 'meta-inf'},
[filename: 1])
# Get all services sorted by order meta
services: ->
@getCollection("documents")
.findAllLive(
{url:$startsWith: "/services"},
[order:1, filename:1])
# Get all tools sorted by order meta
solutions: ->
@getCollection("documents")
.findAllLive(
{url:$startsWith: "/solutions"},
[order: 1, filename: 1])
# Get all rn sorted by order meta + paging included
posts: ->
@getCollection('html')
.findAllLive(
{isPagedAuto:{$ne: true},
basename:{$nin: ['index', 'release_notes']},
filename:{$ne: 'meta-inf'},
url:{$startsWith:"/rn"}},
[filename: -1]).on "add", (model) ->
model.setMetaDefaults(layout:"post")
# Get all services sorted by order meta
APINotebooks: ->
@getCollection("documents")
.findAllLive({
interactive: {$exists: true}
})
#################################
# COLLECTIONS FOR CONTENT #
#################################
servicesContent: ->
@getCollection('services')
.findAllLive({ basename: {$nin: ['meta-inf', 'index']}, title: {$exists: true, $ne: null} })
solutionsContent: ->
@getCollection('solutions')
.findAllLive({ basename: {$nin: ['meta-inf', 'index']}, title: {$exists: true, $ne: null} })
postsContent: ->
@getCollection('posts')
.findAllLive({ headline: {$exists: true, $ne: null} })
# =================================
# Plugins
plugins:
text:
matchElementRegexString: 't'
functions:
writeAfter: [gulpFunctions.replaceApiReferences]
generateAfter: [gulpFunctions.fixTables, gulpFunctions.serviceLatest]
docpadReady: [validate]
# customize marked to use mermaid diagrams
marked: require './helpers/markedRenderer.js'
# =================================
# 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
# =================================
# * Environments
#
environments:
prod:
templateData:
site:
url: process.env.docuURL || "https://yaas.github.io/chewie-sample-result"
blogFeed: "/atom.xml"
googleAnalytics: deployment.googleAnalytics
scripts: deployment.scripts
headScripts: deployment.headScripts
styles: deployment.styles
plugins:
gulp: deployment.gulp
}
# Export our DocPad Configuration
module.exports = docpadConfig