-
Notifications
You must be signed in to change notification settings - Fork 18
/
metalsmith.js
88 lines (83 loc) · 2.11 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var Handlebars = require('handlebars');
var Metalsmith = require('metalsmith');
var date = require('metalsmith-date-in-filename');
var paths = require('metalsmith-paths');
var collections = require('metalsmith-collections');
var permalinks = require('metalsmith-permalinks');
var layouts = require('metalsmith-layouts');
var pagination = require('metalsmith-pagination');
var assets = require('metalsmith-assets');
var browserify = require('metalsmith-browserify');
var thumbnail = require('./src/thumbnail');
Handlebars.registerHelper('each-reverse', require('diy-handlebars-helpers/lib/each-reverse'));
module.exports = Metalsmith(__dirname)
.source('posts')
.destination('animations')
.metadata({
title: 'Animations',
baseurl: '/animations'
})
.use(date({
override: true
}))
.use(paths({
property: 'paths'
}))
.use(collections({
posts: '**'
}))
.use(function (files, metalsmith, done) {
Object.keys(files).forEach(function (name) {
if (/\.glsl$/.test(name)) {
var data = files[name];
data.layout = 'glsl.html';
delete files[name];
files[name.replace(/\.glsl$/, '.html')] = data;
files['static/' + name.replace(/\.glsl$/, '.png')] = {
contents: thumbnail(data.contents)
}
}
});
done();
})
.use(permalinks({
pattern: ':date',
date: 'YYYY-MM-DD',
relative: false
}))
.use(pagination({
posts: {
perPage: 100,
path: ':num',
layout: 'index.html',
first: 'index.html',
noPageOne: true
}
}))
.use(layouts({
engine: 'handlebars',
default: 'default.html'
}))
.use(assets({
source: 'assets',
destination: '.'
}))
.use(browserify('glsl.js', ['src/glsl.js']));
if (process.argv[2] === 'serve') {
var serve = require('metalsmith-serve');
var watch = require('metalsmith-watch');
module.exports
.use(watch({
paths: {
'${source}/**/*': true,
'src/glsl.js': '**/*'
}
}))
.use(serve({
document_root: '.',
port: process.env.PORT
}));
}
module.exports.build(function (err) {
if (err) throw err;
});