aboutsummaryrefslogtreecommitdiffstats
path: root/docs/config/processors/index-page.js
blob: 37a274ec9b97a8bdfe6b7e65a07de03897e2e3a3 (plain)
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
var _ = require('lodash');
var log = require('winston');
var path = require('canonical-path');
var deployment;

module.exports = {
  name: 'index-page',
  runAfter: ['adding-extra-docs'],
  runBefore: ['extra-docs-added'],
  description: 'This processor creates docs that will be rendered as the index page for the app',
  init: function(config) {
    deployment = config.deployment;
    if ( !deployment || !deployment.environments ) {
      throw new Error('No deployment environments found in the config.');
    }
  },
  process: function(docs) {

    // Collect up all the areas in the docs
    var areas = {};
    _.forEach(docs, function(doc) {
      if ( doc.area ) {
        areas[doc.area] = doc.area;
      }
    });
    areas = _.keys(areas);

    _.forEach(deployment.environments, function(environment) {

      var indexDoc = _.defaults({
        docType: 'indexPage',
        areas: areas
      }, environment);

      indexDoc.id = 'index' + (environment.name === 'default' ? '' : '-' + environment.name);
      // Use .. to put it at the root of the build
      indexDoc.outputPath = indexDoc.id + '.html';

      docs.push(indexDoc);
    });
  }
};