Repository navigation
Expand file tree
/
Copy pathbuild.js
More file actions
178 lines (173 loc) · 6 KB
/
Copy pathbuild.js
File metadata and controls
178 lines (173 loc) · 6 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
"use strict";
const metalsmith = require('metalsmith');
const branch = require('metalsmith-branch');
const data_markdown = require('metalsmith-data-markdown');
const debug = require('metalsmith-debug');
const define = require('metalsmith-define');
const filenames = require('metalsmith-filenames');
const fingerprint = require('metalsmith-fingerprint-ignore');
const ignore = require('metalsmith-ignore');
const inplace = require('metalsmith-in-place');
const json_to_files = require('metalsmith-json-to-files');
const layouts = require('metalsmith-layouts');
const metadata = require('metalsmith-metadata');
const models = require('metalsmith-models');
const permalinks = require('metalsmith-permalinks');
const serve = require('metalsmith-serve');
const stylus = require('metalsmith-stylus');
const tidy = require('metalsmith-html-tidy');
const uglify = require('metalsmith-uglify');
const watch = require('metalsmith-watch');
// This is a plugin.
// Lets 'node build' run lean, while 'node build dev' loads add'l plugins.
// TODO: make it a real plugin.
const devonly = function(plugin, options) {
if (process.argv.length > 2 && process.argv.indexOf('dev') > 0) {
return plugin(options);
}
else {
return function(files, metalsmith, done) {
done();
};
}
};
// This is a plugin.
// Dumps some variables to the screen.
// TODO: make it a real plugin.
const dump = function(options) {
return function(files, metalsmith, done) {
console.log(metalsmith);
done();
};
};
metalsmith(__dirname)
// Input files from source directory.
.source('source')
// Define some global values that will be accessible in metadata anywhere.
.use(define({
date_format: 'j F, Y',
version_date: new Date().toISOString(),
}))
// Add debug messages to terminal. Dev-only.
.use(devonly(debug, {}))
// Give each file processed a name during conversion, which is required for
// template inheritance in swig. Conflicts with branch so run it out here.
// https://github.com/MoOx/metalsmith-filenames/issues/1
.use(filenames())
// Restrict the files we transform to a pattern; don't transform 2015.
.use(branch('!2015/**/*')
.use(branch('!berlin-2016/**/*')
.use(branch('!assets/**/*')
// Also put stuff from source/data into collections.
.use(json_to_files({
source_path: 'source/data/',
}))
// Ignore files that we don't want to copy to build dir.
// Must follow json_to_files
.use(ignore([
'**/_*',
'**/*swp',
// At launch we may not have a seattle event. This prevents building its pages.
// '**/seattle-2016/*',
]))
// Put yaml from source/data into global metadata. Must be above inplace.
.use(metadata({
conferences: 'data/conferences.yaml',
navigation: 'data/navigation.yaml',
london_speakers: 'data/london_speakers.yaml',
london_venue: 'data/london_venue.yaml',
}))
// Make pretty urls by moving foo.html to /foo/index.html.
// Also, add a 'path' to global metadata for each file.
.use(permalinks({
relative: false,
}))
// Minimize and concatenate js files. Must be above fingerprint.
.use(uglify({
filter: 'js/*.js',
sourceMap: true,
concat: 'js/main.js',
}))
// Convert stylus files to css. Must be above fingerprint.
.use(stylus({
compress: true
}))
// Change asset filenames to unique strings per build for cachebusting.
// Must be above inplace.
.use(fingerprint({
pattern: ['stylesheets/style.css', 'js/*.js'],
}))
// Process template files in the source dir using specified engine.
.use(inplace({
engine: 'swig',
pattern: ['**/*.html', 'worker.js'],
autoescape: false,
}))
// Apply layouts to (certain) source files using specified engine.
// We only use this to support json_to_files.
.use(layouts({
engine: 'swig',
pattern: '**/*.html',
autoescape: false,
}))
// Convert GFM content inside tags with "data-markdown" attribute.
// Should be after all swig stuff.
.use(data_markdown({
marked: {
gfm: true,
breaks: true,
tables: false,
smartlists: true,
smartypants: true,
},
removeAttributeAfterwards: true,
}))
// Tidy HTML
.use(tidy({
tidyOptions: {
'indent-spaces': 4,
'quote-ampersand': false,
'coerce-endtags': false,
'drop-empty-elements': false,
'new-blocklevel-tags': ['svg', 'defs', 'path', 'polyline', 'line', 'polygon',],
},
}))
// Log global metadata, etc., to terminal.
.use(devonly(dump))
)))
// Output files to build dir.
.destination('build')
// Automatically rebuild things in the source directory when they change.
.use(devonly(watch, {
paths: {
'source/assets/**/*': true,
'source/*2016/**/*': true,
'source/js/**/*': true,
'source/stylesheets/**/*': true,
'source/*': true,
'source/data/**/*': '**/*',
'layouts/**/*': '**/*',
},
livereload: true,
}))
// Start a server on localhost.
.use(devonly(serve, {
host: '0.0.0.0',
port: 8080,
verbose: true,
http_error_files: {
404: "/404.html",
},
}))
.use(devonly(define, {
livereload: '<script src="http://localhost:35729/livereload.js"></script>',
}))
// Do it!
.build(function(err) {
if (err) {
console.log(err);
}
else {
console.info('✫ Built it. ✫');
}
});