forked from metalsmith/metalsmith.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetalsmith.js
More file actions
113 lines (105 loc) · 2.67 KB
/
metalsmith.js
File metadata and controls
113 lines (105 loc) · 2.67 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
/* eslint-disable import/no-extraneous-dependencies */
const inPlace = require('metalsmith-in-place');
const layouts = require('metalsmith-layouts');
const when = require('metalsmith-if');
const favicons = require('metalsmith-favicons');
const postcss = require('metalsmith-postcss');
const browserify = require('metalsmith-browserify');
const uglify = require('metalsmith-uglify');
const htmlMinifier = require('metalsmith-html-minifier');
const imagemin = require('metalsmith-imagemin');
const metalsmith = require('metalsmith');
const examples = require('./lib/data/examples.json');
const plugins = require('./lib/data/plugins.json');
const nodeVersion = process.version;
const githubRegex = /github\.com\/([^/]+)\/([^/]+)\/?$/;
const oneWeek = 7 * 24 * 60 * 60;
const mappedPlugins = plugins.map(plugin => {
const result = githubRegex.exec(plugin.repository);
if (result) {
const [, user, repo] = result;
const npm = plugin.npm || repo;
Object.assign(plugin, {
respositoryIssues: `${plugin.repository}/issues`,
npmUrl: `https://www.npmjs.com/package/${npm}`,
npmDownloads: `https://img.shields.io/npm/dy/${npm}.svg?maxAge=${oneWeek}`,
npmVersion: `https://img.shields.io/npm/v/${npm}.svg?maxAge=${oneWeek}`,
githubStars: `https://img.shields.io/github/stars/${user}/${repo}.svg?maxAge=${oneWeek}`
});
}
return plugin;
});
const isProduction = process.env.NODE_ENV === 'production';
metalsmith(__dirname)
.metadata({
placeholderBadgeUrl: 'https://img.shields.io/badge/badge-loading-lightgrey.svg?style=flat',
plugins: mappedPlugins,
examples,
nodeVersion
})
.use(
when(
isProduction,
favicons({
src: 'favicons/favicon.png',
dest: 'favicons/',
icons: {
android: true,
appleIcon: true,
favicons: true
}
})
)
)
.use(
inPlace({
engineOptions: {
smartypants: true,
smartLists: true
},
pattern: '**/*.md'
})
)
.use(
layouts({
directory: 'lib/views',
pattern: '**/*.html'
})
)
.use(
browserify({
entries: ['index.js']
})
)
.use(
postcss({
plugins: [
'postcss-easy-import',
'postcss-custom-media',
'postcss-preset-env',
{
'postcss-normalize': { forceImport: true }
},
'autoprefixer',
'cssnano'
],
map: {
inline: false
}
})
)
.use(when(isProduction, htmlMinifier()))
.use(when(isProduction, imagemin()))
.use(
when(
isProduction,
uglify({
sameName: true
})
)
)
.build(err => {
if (err) {
throw err;
}
});