Skip to content
This repository has been archived by the owner on Aug 3, 2022. It is now read-only.

Commit

Permalink
[#853] Generate ancillary pages
Browse files Browse the repository at this point in the history
Ancillary pages are added to the CMS under keys ending with `_page`.
This commit adds a metalsmith plugin to generate pages from content
under those keys.
  • Loading branch information
brew committed Jan 31, 2017
1 parent 0f3cf02 commit da3ceba
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 28 deletions.
2 changes: 1 addition & 1 deletion census/loaders/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let loadConfig = function(siteId, models) {
const raw = _.object(_.zip(_.pluck(indexConfig, 'key'), _.pluck(indexConfig, 'value')));
_.each(raw, (v, k) => {
if (v && k.endsWith('_page')) {
indexSettings[k] = marked(v);
indexSettings[k] = v;
} else {
indexSettings[k] = v;
}
Expand Down
50 changes: 32 additions & 18 deletions census/views/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,39 @@

<ul class="menu">
{% if is_index %}
<li><a href="/place/">{{ gettext("Places") }}</a></li>
<li><a href="/dataset/">{{ gettext("Datasets") }}</a></li>
{% endif %}
<li><a href="/about/">{{ gettext("About") }}</a></li>
<li><a href="/changes/">{{ gettext("Changes") }}</a></li>
<li><a href="/faq/">{{ gettext("FAQ") }}</a></li>
{% if site.settings.methodology_page %}
<li><a href="/methodology/">{{ gettext("Methodology") }}</a></li>
{% endif %}
{% if site.settings.contribute_page %}
<li><a href="/contribute/">{{ gettext("Contribute") }}</a></li>
{% endif %}
{% if site.settings.tutorial_page %}
<li><a href="/tutorial/">{{ gettext("Tutorial") }}</a></li>
<li><a href="/place/">{{ gettext("Places") }}</a></li>
<li><a href="/dataset/">{{ gettext("Datasets") }}</a></li>
{% if 'insights' in ancillary_pages %}
<li><a href="/insights/">{{ gettext("Insights") }}</a></li>
{% endif %}
{% if 'methodology' in ancillary_pages %}
<li><a href="/methodology/">{{ gettext("Methodology") }}</a></li>
{% endif %}
{% if 'about' in ancillary_pages %}
<li><a href="/about/">{{ gettext("About") }}</a></li>
{% endif %}
{% if 'press' in ancillary_pages %}
<li><a href="/press/">{{ gettext("Press") }}</a></li>
{% endif %}
{% endif %}
{% if site.settings.support_url %}
<li><a target="_blank" href="{{ site.settings.support_url }}">{{ gettext("Support") }}</a></li>
{% elif discussionForum %}
<li><a target="_blank" href="{{ discussionForum }}">{{ gettext("Support") }}</a></li>
{% if not is_index %}
<li><a href="/about/">{{ gettext("About") }}</a></li>
<li><a href="/changes/">{{ gettext("Changes") }}</a></li>
<li><a href="/faq/">{{ gettext("FAQ") }}</a></li>
{% if site.settings.methodology_page %}
<li><a href="/methodology/">{{ gettext("Methodology") }}</a></li>
{% endif %}
{% if site.settings.contribute_page %}
<li><a href="/contribute/">{{ gettext("Contribute") }}</a></li>
{% endif %}
{% if site.settings.tutorial_page %}
<li><a href="/tutorial/">{{ gettext("Tutorial") }}</a></li>
{% endif %}
{% if site.settings.support_url %}
<li><a target="_blank" href="{{ site.settings.support_url }}">{{ gettext("Support") }}</a></li>
{% elif discussionForum %}
<li><a target="_blank" href="{{ discussionForum }}">{{ gettext("Support") }}</a></li>
{% endif %}
{% endif %}
</ul>
</nav>
Expand Down
2 changes: 2 additions & 0 deletions index/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const i18n = require('i18n-abide');

const godiGetData = require('./metalsmith-godi-getdata');
const godiDataFiles = require('./metalsmith-godi-updatedatafiles');
const godiAncillaryFiles = require('./metalsmith-godi-ancillaryfiles');
const jsonToFiles = require('metalsmith-json-to-files');

const templatePath = path.join(__dirname, '../census/views/');
Expand Down Expand Up @@ -62,6 +63,7 @@ Metalsmith(__dirname)
.use(godiGetData({domain: domain, year: 2016})) // Populate metadata with data from Survey
.use(jsonToFiles({use_metadata: true}))
.use(godiDataFiles()) // Add file metadata to each entry file populated by json-to-files
.use(godiAncillaryFiles({domain: domain}))
.use(markdown())
.use(permalinks())
.use(paths({property: 'paths', directoryIndex: 'index.html'}))
Expand Down
47 changes: 47 additions & 0 deletions index/metalsmith-godi-ancillaryfiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

const _ = require('lodash');

const debug = require('debug')('metalsmith-godi-ancillaryfiles');

const models = require('../census/models');

module.exports = plugin;

/**
* GODI Metalsmith plugin that locates anillary page content present in the
* Index settings object and adds each page as a file to be built by
* Metalsmith.
*
* Ancillary pages have a key ending with `_page`, e.g. about_page.
*
* @return {Function}
*/

function plugin(options) {
return (files, metalsmith, done) => {
let metadata = metalsmith.metadata();
debug('Adding ancillary pages.');
models.Site.findById(options.domain)
.then(site => {
// Get ancillary page content from Index settings.
const indexSettings = site.indexSettings;
metadata.ancillary_pages = [];
_.each(indexSettings, (v, k) => {
if (_.endsWith(k, '_page') && v) {
const keyName = k.split('_page')[0];
const fileData = {
title: _.capitalize(keyName),
layout: 'page.html',
breadcrumbTitle: _.capitalize(keyName),
contents: v
};
files[keyName + '.md'] = fileData;
metadata.ancillary_pages.push(keyName);
}
});
done();
})
.catch(err => done(err));
};
}
5 changes: 0 additions & 5 deletions index/src/about.md

This file was deleted.

4 changes: 0 additions & 4 deletions index/src/methodology.md

This file was deleted.

0 comments on commit da3ceba

Please sign in to comment.