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