diff --git a/docs/lib/changelog.js b/docs/lib/changelog.js new file mode 100644 index 00000000..1054e6f3 --- /dev/null +++ b/docs/lib/changelog.js @@ -0,0 +1,17 @@ +const {readFileSync} = require('fs') + +module.exports = function addChangelog(sourcePath, destPath, transform = noop) { + return (files, metal, done) => { + const path = metal.path(metal.source(), sourcePath) + const file = { + contents: readFileSync(path), + path: destPath + } + transform(file) + files[destPath] = file + done() + } +} + +function noop() { +} diff --git a/docs/lib/sync.js b/docs/lib/sync.js index 56f7c4b8..97d27575 100644 --- a/docs/lib/sync.js +++ b/docs/lib/sync.js @@ -3,6 +3,7 @@ const filter = require('metalsmith-filter') const frontmatter = require('metalsmith-matters') const watch = require('metalsmith-watch') +const addChangelog = require('./changelog') const addPackageMeta = require('./add-package-meta') const addSource = require('./add-source') const filterBy = require('./filter-by') @@ -53,14 +54,18 @@ module.exports = function sync(options = {}) { ) // rename files with their "path" frontmatter key .use(rename(file => `${file[ns].path}.md`), {log}) - // write frontmatter back out to the file - .use(writeMeta(metaOptions)) + .use(addChangelog('../CHANGELOG.md', 'whats-new/changelog.md', file => { + file[ns] = { + title: 'Changelog' + } + })) // read the changelog manually .use((_files, metal, done) => { - _files['whats-new/changelog.md'] = metal.readFile('../CHANGELOG.md') files = _files done() }) + // write frontmatter back out to the file + .use(writeMeta(metaOptions)) // keep .gitignore up-to-date with the list of generated files .use( gitIgnore({