1 | path = require('path')
|
2 | _ = require('lodash')
|
3 |
|
4 | defaultConfig =
|
5 | docsExt: 'md'
|
6 | sourceDir: 'pages'
|
7 | destDir: 'contents'
|
8 | templatesDir: 'templates'
|
9 | defaultTemplate: 'default.html'
|
10 | partialsDir: 'shared'
|
11 | dictionariesDir: true
|
12 | metaExtra: null
|
13 | layoutLocals: null
|
14 |
|
15 | defaultConfigOptional =
|
16 | dictionariesDir: 'config/dictionaries'
|
17 | parseNav: 'config/navigation.txt'
|
18 | serializeNav: 'nav.json'
|
19 | buildLunrIndex: 'lunr_index.json'
|
20 |
|
21 | resolvePathKeys = [
|
22 | 'dictionariesDir'
|
23 | 'parseNav'
|
24 | 'serializeNav'
|
25 | 'buildLunrIndex'
|
26 | ]
|
27 |
|
28 | requiredKeys = [
|
29 | 'rootDir'
|
30 | 'sourceDir'
|
31 | 'destDir'
|
32 | ]
|
33 |
|
34 | module.exports = (userConfig) ->
|
35 | config = _.defaults({}, userConfig, defaultConfig)
|
36 |
|
37 | for key, value of defaultConfigOptional
|
38 | config[key] = value if config[key] is true
|
39 |
|
40 | for key in requiredKeys
|
41 | if not config[key]
|
42 | throw new Error("The key #{key} is required for Doxx config")
|
43 |
|
44 | for key in resolvePathKeys
|
45 | if config[key]
|
46 | config[key] = path.resolve(config.rootDir, config[key])
|
47 |
|
48 | if config.serializeNav and not config.parseNav
|
49 | throw new Error("parseNav key is required when serializeNav is defined in Doxx config")
|
50 |
|
51 | return config
|