-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetalsmith.js
95 lines (81 loc) · 2.22 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
89
90
91
92
93
94
95
/* eslint-disable import/no-extraneous-dependencies */
const Metalsmith = require("metalsmith");
const markdown = require("@metalsmith/markdown");
const layouts = require("@metalsmith/layouts");
const collections = require("@metalsmith/collections");
const drafts = require("@metalsmith/drafts");
const permalinks = require("@metalsmith/permalinks");
const when = require("metalsmith-if");
const htmlMinifier = require("metalsmith-html-minifier");
const assets = require("metalsmith-static-files");
const metadata = require("@metalsmith/metadata");
const prism = require("metalsmith-prism");
const { dependencies } = require("./package.json");
const isProduction = process.env.NODE_ENV === "production";
// functions to extend Nunjucks environment
const spaceToDash = string => string.replace(/\s+/g, "-");
const condenseTitle = string => string.toLowerCase().replace(/\s+/g, "");
const UTCdate = date => date.toUTCString("M d, yyyy");
const blogDate = date => date.toLocaleString("en-US", { year: "numeric", month: "long", day: "numeric" });
const trimSlashes = string => string.replace(/(^\/)|(\/$)/g, "");
// Define engine options for the inplace and layouts plugins
const templateConfig = {
directory: "layouts",
engineOptions: {
smartypants: true,
smartLists: true,
filters: {
spaceToDash,
condenseTitle,
UTCdate,
blogDate,
trimSlashes,
},
},
};
Metalsmith(__dirname)
.source("./src/content")
.destination("./build")
.clean(true)
.metadata({
msVersion: dependencies.metalsmith,
nodeVersion: process.version,
})
.use(when(isProduction, drafts()))
.use(
metadata({
site: "src/content/data/site.json",
nav: "src/content/data/navigation.json",
})
)
.use(
collections({
blog: {
pattern: "blog/*.md",
sortBy: "date",
reverse: true,
limit: 10,
},
})
)
.use(markdown())
.use(permalinks({relative: false}))
.use(layouts(templateConfig))
.use(
prism({
lineNumbers: true,
decode: true,
})
)
.use(
assets({
source: "src/assets/",
destination: "assets/",
})
)
.use(when(isProduction, htmlMinifier()))
.build(err => {
if (err) {
throw err;
}
});