-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
75 lines (72 loc) · 1.96 KB
/
build.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
68
69
70
71
72
73
74
75
const metalsmith = require('metalsmith')(__dirname);
const collections = require('metalsmith-collections');
const dateInFilename = require('metalsmith-date-in-filename');
const helpers = require('./helpers');
const inPlace = require('metalsmith-in-place');
const layouts = require('metalsmith-layouts');
const markdown = require('@attentif/metalsmith-markdownit');
const markdownBracketedSpans = require('markdown-it-bracketed-spans');
const markdownAttrs = require('markdown-it-attrs');
const metadata = require('./metadata');
const nib = require('nib');
const permalinks = require('metalsmith-permalinks');
const stylus = require('metalsmith-stylus');
const watch = process.argv[2] === 'watch' ? require('metalsmith-watch') : null;
metalsmith
.source('./src')
.destination('./build')
.clean(false) // to keep .git, CNAME etc.
.metadata(Object.assign(metadata, {
helpers: helpers
}))
.ignore(['_*'])
.use(dateInFilename({
override: false
}))
.use(collections({
articles: {
pattern: 'a/*.md*',
sortBy: 'date',
reverse: true
},
lastArticles: {
pattern: 'a/*.md*',
sortBy: 'date',
reverse: true,
limit: metadata.lastArticlesCount
}
}))
.use(inPlace({
suppressNoFilesError: true,
setFilename: true
}))
.use(markdown({
html: true,
linkify: true,
typographer: true
}).use(markdownBracketedSpans).use(markdownAttrs))
.use(permalinks({
relative: false
}))
.use(layouts({
directory: 'src/_layouts',
default: 'default.pug',
pattern: '**/*.html'
}))
.use(stylus({
use: [nib()]
}));
if (watch) {
metalsmith.use(watch({
paths: {
// changed sources: rebuild all (should be true to only rebuild changes but the
// in-place plugin apparently mistakingly fails not finding files to process
'src/**/*': '**/*',
'layouts/**/*': '**/*'
}
}));
}
metalsmith.build(function (err) {
if (err) { return console.error(err); }
console.log('OK');
});