forked from cozy/cozy-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docpad.coffee
69 lines (54 loc) · 2.17 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
# DocPad Configuration File
# http://docpad.org/docs/config
# Define the DocPad Configuration
docpadConfig = {
outPath: 'public'
templateData:
site:
url: "http://cozy.io/"
title: ""
description: ""
keywords: ""
getLang: (document) ->
[lang, ...] = document.relativePath.split '/'
return lang
collections:
hostPagesFR: ->
@getCollection('html').findAllLive category: 'host', url:$startsWith: '/fr'
hostPagesEN: ->
@getCollection('html').findAllLive category: 'host', url:$startsWith: '/en'
mobilePagesFR: ->
@getCollection('html').findAllLive category: 'mobile', url:$startsWith: '/fr'
mobilePagesEN: ->
@getCollection('html').findAllLive category: 'mobile', url:$startsWith: '/en'
hackPagesFR: ->
@getCollection('html').findAllLive category: 'hack', url:$startsWith: '/fr'
hackPagesEN: ->
@getCollection('html').findAllLive category: 'hack', url:$startsWith: '/en'
homePages: ->
@getCollection('html').findAllLive isCategoryMaster:$exists:true
events:
contextualizeAfter: (options) ->
{collection} = options
# rewrite the layout meta data to prepend the locale information
collection.each (model) ->
layout = model.get 'layout'
# assets files have don't have "layout" info
if layout?
[lang, ...] = model.get('relativePath').split '/'
newLayout = "#{lang}/#{layout}"
model.set 'layout', newLayout
render: (options) ->
{content, file} = options
layout = file.get 'layout'
if layout?
[lang, ...] = file.get('relativePath').split '/'
# rewrite URLs to prepend language
regex = /["]{1}\/(hack|host|mobile)/g
content = content.replace regex, "\"/#{lang}/$1"
options.content = content
enabledPlugins:
"live-reload": true
}
# Export the DocPad Configuration
module.exports = docpadConfig