-
Notifications
You must be signed in to change notification settings - Fork 5
/
metalsmith.js
67 lines (59 loc) · 2.14 KB
/
metalsmith.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* eslint no-return-assign: 0 */
/* eslint no-unused-vars: 0 */
import Metalsmith from 'metalsmith';
import _ from 'lodash';
import collections from 'metalsmith-collections';
import paths from 'metalsmith-paths';
import {parse, transform} from 'metalsmith-transmark';
import {markdownMetaMarker} from 'transmark';
import {plugin as drafts} from './lib/drafts';
import {plugin as render} from './lib/render';
import {material, activity, methodology} from './lib/transformation';
import {sections} from './config/base-settings';
const order = _.map(sections, 'title'); // set the order collections in the data.json file
// create an object to supply to the metaalsmith-collections plugin
const collectionsObj = _.reduce(sections, (memo, section) =>
_.merge(memo, {[section.title]: section.files})
, {});
// create an object to supply to the metalsmith-transmark.parse plugin's extension argument
const parseExtNames = _.filter(sections, (section) => (section.parse));
const parseExtensions = () => {
let parseStr = '[\u000A';
_.forEach(parseExtNames, (ext) =>
parseStr = `${parseStr} markdownMetaMarker('${ext.metaTitle}'), \u000A`
);
parseStr = `${parseStr}\u000A]`;
return parseStr;
};
const parserMeta = _.reduce(parseExtNames, (memo, section) =>
_.merge(memo, {[section.title]: []})
, {});
new Metalsmith(__dirname)
.metadata({
transmark: {},
})
// TODO:10 This is not nice, I should whitelist directories, rather than
// blacklisting.
.ignore(['node_modules', 'index.html', '.git', 'metalsmith.js', '.babelrc', '.eslintrc',
'_*.md', '.gitignore', 'test.json', 'lib', '**/*.png', '**/*.pdf', 'package.json', 'README'])
.source('./content')
.destination('./public/data')
.use(drafts())
// #done:0 Remove the dependency to metalsmith-paths.
.use(paths())
.use(collections(collectionsObj))
.use(parse({
extensions:
[
markdownMetaMarker('methodology'),
markdownMetaMarker('material'),
markdownMetaMarker('activity')
],
meta: parserMeta,
order
}))
.use(transform({handlers: {material, activity, methodology}, order}))
.use(render())
.build(err => {
if (err) { throw err; }
});