-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
99 lines (94 loc) · 2.39 KB
/
index.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var Metalsmith = require('metalsmith');
var markdown = require('@metalsmith/markdown');
var layouts = require('@metalsmith/layouts');
var sass = require('@metalsmith/sass');
var metadata = require('@metalsmith/metadata');
var collections = require('@metalsmith/collections');
var filepath = require('metalsmith-filepath');
var inplace = require('@metalsmith/in-place');
var ignore = require('metalsmith-ignore');
var define = require('metalsmith-define');
var defaultVals = require('@metalsmith/default-values');
var url = require('url');
var serveMode = process.argv.indexOf('--serve') != -1;
var site = Metalsmith(__dirname)
.source('./src')
.destination('./build')
.use(defaultVals({
pattern: '*',
serve: serveMode,
}))
.use(ignore(['**/.DS_Store']))
.use(metadata({
course: 'src/course.yaml',
schedule: 'src/schedule.yaml',
content: 'src/content.yaml',
}))
.use((files, metalsmith, done) => {
// Merge schedule with content.
var schedule = metalsmith._metadata.schedule;
var content = metalsmith._metadata.content;
var cont_i = 0;
for (var sched_i = 0; sched_i < schedule.length; sched_i++) {
var day = schedule[sched_i];
if (!day.event && !day.canceled) {
// Allocate a content element.
Object.assign(day, content[cont_i]);
cont_i++;
}
}
done();
})
.use(collections({
pages: {
pattern: '*.{md,html,pug,hbs}',
sort: 'order',
}
}))
.use(define({
resolve: url.resolve, // Path join helper.
relative: function (link) {
if (link[0] === '/') {
return link.slice(1);
} else {
return link;
}
},
}))
.use(inplace({
transform: 'handlebars',
setFilename: true,
}))
.use(inplace({
transform: 'pug',
setFilename: true,
}))
.use(markdown({
smartypants: true,
}))
.use(sass())
.use(filepath({
absolute: true
}))
.use(layouts({
default: 'layout.hbs',
pattern: ['**/*.html'],
suppressNoFilesError: serveMode,
}));
if (serveMode) {
var serve = require('metalsmith-serve');
var watch = require('metalsmith-watch');
site = site
.use(serve())
.use(watch({
paths: {
"${source}/**/*": true,
"layouts/**/*": "**/*.md",
"${source}/**/*.yaml": "**/*",
},
livereload: true
}));
}
site.build(function(err) {
if (err) throw err;
});