-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathmetalsmith.js
More file actions
135 lines (125 loc) · 3.08 KB
/
metalsmith.js
File metadata and controls
135 lines (125 loc) · 3.08 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
var Metalsmith = require('metalsmith');
var drafts = require('metalsmith-drafts');
var markdown = require('metalsmith-markdown');
var excerpts = require('metalsmith-excerpts');
var layouts = require('metalsmith-layouts');
var collections = require('metalsmith-collections');
var feed = require('metalsmith-feed');
var serve = require('metalsmith-serve');
var watch = require('metalsmith-watch');
var assets = require('metalsmith-assets');
var sass = require('metalsmith-sass');
var nunjucks = require('nunjucks');
var nunjucksDate = require('nunjucks-date');
var metalsmith = Metalsmith(__dirname);
// General Options for build process
var options = {
source_dir : 'src',
dist_dir : 'dist',
layout_dir : 'src/layouts',
watch: {
"${source}/**/*.md": true,
'src/layouts/**/*' : "**/*",
'src/sass/**/*.scss' : "**/*.scss",
},
port: 8080,
assets: {
source: './src/assets', // relative to the working directory
destination: './assets' // relative to the build directory
}
}
// Metadata to be passed to templates
var metadata = {
categories: [
{
"collection": "articles",
"title": "Articles"
},
{
"collection": "videos",
"title": "Videos"
},
{
"collection": "tools",
"title": "Tools"
},
{
"collection": "talks",
"title": "Talks"
}
],
site: {
description: "Welcome to the ultimate collection of Visual Regression Testing resources. Find articles, video tutorials about visual testing, and browse our list of testing tools to get your project up and running.",
title: "Visual Regression Testing",
url: "http://visualregressiontesting.com",
author: "Micah Godbolt & Kevin Lamping"
}
}
// Page collections like all pages or all posts
var site_collections = {
all: {
pattern: 'content/**/*.md'
},
articles: {
pattern: 'content/articles/*.md'
},
videos: {
pattern: 'content/videos/*.md'
},
tools: {
pattern: 'content/tools/*.md'
},
talks: {
pattern: 'content/talks/*.md'
},
pages: {
pattern: '*.md',
sortBy: 'position'
}
}
// Need to add configuration to nunjucks that metalsmith cannot
nunjucks
.configure(options.layout_dir, {watch: false, noCache: true})
.addFilter('date', nunjucksDate);
nunjucksDate
.setDefaultFormat('MMMM Do, YYYY');
// if SERVE is set to true, server is started and files are watched
if (process.env.SERVE) {
metadata.serve = true;
metalsmith
.use(serve({
port: options.port
}))
.use(watch({
paths: options.watch,
livereload: true
}));
}
// Run Metalsmith
metalsmith
.metadata(metadata)
.source(options.source_dir)
.clean(true)
.use(drafts(true))
.use(collections(site_collections))
.use(markdown())
.use(excerpts())
.use(assets(options.assets))
.use(feed({
collection: 'all'
}))
.use(sass({
outputDir: 'css/'
}))
.use(layouts({
engine: 'nunjucks',
directory: options.layout_dir
}))
.destination(options.dist_dir)
.build(function (err, files) {
if (err) {
console.log('Error!');
console.log(err);
throw err;
}
});