This repository has been archived by the owner on Aug 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
6 changed files
with
82 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.