forked from billiegoose/hubo-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docpad.coffee
71 lines (57 loc) · 1.89 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
# DocPad Configuration File
# http://docpad.org/docs/config
# Define the DocPad Configuration
docpadConfig = {
maxAge: 86400000
# Ignore GIMP files
ignoreCustomPatterns: /\.ignore/
# Configure Plugins
# Should contain the plugin short names on the left, and the configuration to pass the plugin on the right
plugins: # example
jade:
jadeOptions:
basedir: 'src/layouts'
pretty: on
coffeescript:
compileOptions:
bare: on
header: on
sourceMap: on
stylus:
stylusLibraries:
nib: on
stylusOptions:
compress: off
# =================================
# 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:
renderDocument: (opts,next) ->
{extension, templateData, file, content} = opts
path = require('path')
compute = (from, to) ->
return (path.relative(path.dirname(from), to) || '.').replace("\\","/") + '/'
relativizeCSS = (source, relativeRoot) ->
return (source
.replace(/(url\(['"])\/(?!\/)/g, "$1"+relativeRoot)
.replace(/\{local_root\}/g, relativeRoot))
relativizeHTML = (source, relativeRoot) ->
return (source
.replace(/(href=["'])\/(?!\/)/g, '$1'+relativeRoot)
.replace(/(src=["'])\/(?!\/)/g, '$1'+relativeRoot)
.replace(/\{local_root\}/g, relativeRoot))
if file.type is 'document'
root = @docpad.getConfig().outPath
relativeRoot = compute(file.attributes.outPath, root)
switch extension
when 'html'
opts.content = relativizeHTML(content,relativeRoot)
when 'css', '.styl'
opts.content = relativizeCSS(content,relativeRoot)
return next()
# Chain
@
}
# Export the DocPad Configuration
module.exports = docpadConfig