forked from brikkho-net/doc.nuxeo.com-content
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-frontmatter.js
58 lines (48 loc) · 1.41 KB
/
update-frontmatter.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
'use strict';
/* eslint no-console: 0, new-cap: 0 */
const module_name = 'update-frontmater';
// Set Debugging up
if (!process.env.DEBUG) {
process.env.DEBUG = '*:info,*:error';
}
const debug_lib = require('debug');
const Metalsmith = require('metalsmith');
const yaml = require('js-yaml');
const debug = debug_lib(module_name);
// const info = debug_lib(`${module_name}:info`);
// const error = debug_lib(`${module_name}:error`);
const nl = '\n';
const update_frontmatter = options => (files, metalsmith, done) => {
Object.keys(files).forEach(filename => {
debug(`Processing: ${filename}`);
let file = files[filename];
file = options.manipulation(file);
const contents = file.contents;
const frontmatter = Object.assign({}, file);
delete frontmatter.contents;
delete frontmatter.mode;
delete frontmatter.stats;
const yaml_output = yaml.safeDump(frontmatter, { indent: 2 });
file.contents = Buffer.from(`---${nl}${yaml_output}${nl}---${nl}${contents}`, 'utf8');
});
done();
};
console.time('Update Frontmatter');
Metalsmith(__dirname)
.source('./src')
.use(
update_frontmatter({
manipulation: file => {
file.labels = file.labels || [];
file.labels.push('content-review-lts2017');
return file;
}
})
)
.destination('./src_updated')
.build(err => {
if (err) {
throw err;
}
console.timeEnd('Update Frontmatter');
});