-
Notifications
You must be signed in to change notification settings - Fork 0
/
docpad.coffee
80 lines (66 loc) · 2.66 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
# DocPad Configuration File
# http://docpad.org/docs/config
# https://developers.google.com/closure/templates/docs/javascript_usage#compilation
# Define the DocPad Configuration
docpadConfig = {
# ...
templateData:
getToc: (html) -> getToc html
getProtectedEmailLink: (email) -> getProtectedEmailLink email
getEmailProtectionCode: -> getEmailProtectionCode
getPageTitle: -> getPageTitle @document
getBreadcrumbs: -> getBreadcrumbs this
getPageName: -> getPageName @document
getImgPath: (document, img) -> getImgPath document, img
getUrl: -> getUrl @document
collections:
products: -> @getCollection("html").findAll({layout: "product"}, [productName:1])
###
plugins:
grunt:
writeAfter: false
generateAfter: ["cssmin", "uglify"]
###
}
# Export the DocPad Configuration
module.exports = docpadConfig
cononizeUrl = (url) ->
if url.endsWith("index.html") then "" else url
getUrl = (document) ->
'https://www.stellaritysoftware.com' + cononizeUrl(document.url)
getToc = (html) ->
tokens = html.match /<h\d.*?>.*?<\/h\d>/ig
for token in tokens
level: (token.match /<h(\d)/i)?[1]
id: (token.match /id=\"(.*?)\"/i)?[1]
text: (token.match /<h\d.*?>(.*?)<\/h\d>/i)?[1]
getProtectedEmailLink = (email) ->
email = email.replace /@/, "#"
"mailto:sp@@@#{email}sp@@@"
getEmailProtectionCode = "href=href.replace(/sp@@@/g,'').replace(/#/, '@');"
getPageTitle = (document) ->
return document.title if document.title?
return "#{getPageName(document)} | Stellarity Software" if document.layout is "product"
"Stellarity Software | Addons for JIRA, Bamboo and other tools"
getBreadcrumbs = (that) ->
document = that.document
pages = that.getCollection("html")
documentUrl = document.url.replace ".#{document.outExtension}", ""
documentUrl = documentUrl.concat "/"
urls = (documentUrl.slice 0,i for i in [0...documentUrl.length] when (documentUrl.charAt i).toString() is "/")
urls[0] = "/index"
urls = ("#{url}.#{document.outExtension}" for url in urls)
for url in urls
url: url
name: getPageName pages.findOne({url: url}).toJSON()
getPageName = (document) ->
return document.pageName if document.pageName?
return "#{document.productName} for #{document.hostName}" if document.productName?
return uppercaseFirstLetter document.basename
uppercaseFirstLetter = (str) ->
str.charAt(0).toUpperCase() + str.slice(1)
makeSlug = (str) ->
str.toLowerCase().replace(/[\s,:]+/g, '-')
getImgPath = (document, img) ->
slug = makeSlug document.productName
"/img/products/#{slug}/#{img}"