-
Notifications
You must be signed in to change notification settings - Fork 0
/
metalsmith.js
220 lines (212 loc) · 6.07 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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import { fileURLToPath } from 'node:url';
import { dirname } from 'path';
import Metalsmith from 'metalsmith';
import collections from '@metalsmith/collections';
import layouts from '@metalsmith/layouts';
import markdown from '@metalsmith/markdown';
import permalinks from '@metalsmith/permalinks';
import publish from 'metalsmith-publish';
import postcss from '@metalsmith/postcss';
import include from 'metalsmith-include-files';
import concat from 'metalsmith-concat';
import sitemap from 'metalsmith-sitemap';
import toc from '@metalsmith/table-of-contents';
// My plugins
import rss from './bin/rss.js';
import gallery from './bin/gallery.js';
import blog from './bin/blog.js';
import handlebarsDiscoverer from './bin/handlebars-discoverer.js';
import { addDates, bodyClasses, breadcrumbs, github, favicons } from './bin/file-functions.js';
// JSON objects
import packageJson from './package.mjs';
import galleryMetadata from './gallery.mjs';
const __dirname = dirname(fileURLToPath(import.meta.url));
const t1 = performance.now();
const env = process.env.NODE_ENV || 'development';
const devMode = ['development', 'dev'].includes(env);
const melindreamakes = packageJson.melindreamakes;
const repository = packageJson.repository;
function presence (files, metalsmith) {
Object.keys(files).forEach(path => {
if (files[path].presence) {
files[path].presence = melindreamakes.presence;
}
if (files[path].mastodon) {
files[path].mastodon = melindreamakes.mastodon;
}
});
}
function check (files, metalsmith) {
Object.keys(files).forEach(filepath => {
// metalsmith.metadata().collections.blog.forEach(post => {
/* if (post.toc) {
console.log(post.title)
console.log(post.toc)
} */
// Object.keys(files).forEach(path => {
// console.log(path);
// console.log(files[path]);
});
// const thingy = 'blog';
// console.log(metalsmith.metadata().collections[thingy]);
// console.log(metalsmith.metadata().images);
}
// Run Metalsmith in the current directory.
// When the .build() method runs, this reads
// and strips the frontmatter from each of our
// source files and passes it on to the plugins.
Metalsmith(__dirname)
.metadata({
repository,
...melindreamakes.metadata
})
.source('./src') // source directory
.destination('./docs') // destination directory
.clean(true) // clean destination before
.ignore('**/*.DS_Store')
.use(postcss({
plugins: {
'postcss-import': {},
tailwindcss: {},
autoprefixer: {}
}
}))
.use(include({ // include external JavaScript
directories: {
'assets/js': [
'./node_modules/jquery/dist/jquery.slim.min.js'
],
'assets/fonts': [
'./node_modules/lightgallery/fonts/*'
],
'assets/images': [
'./node_modules/lightgallery/images/*'
],
'': [
'favicons/*'
]
}
}))
.use(concat({
files: [
'assets/js/main.max.js' // found in src
],
searchPaths: ['node_modules'],
output: 'assets/js/scripts.max.js'
}))
.use(concat({
files: [
'lightgallery/lightgallery.min.js', // found in node_modules
'lightgallery/plugins/thumbnail/lg-thumbnail.min.js', // found in node_modules
'lightgallery/plugins/zoom/lg-zoom.min.js' // found in node_modules
],
searchPaths: ['node_modules'],
output: 'assets/js/lightgallery.min.js'
}))
// Use @metalsmith/markdown to convert
// our source files' content from markdown
// to HTML fragments.
.use(markdown())
.use(favicons)
.use(addDates)
.use(publish({
futureMeta: 'pubdate',
draft: devMode,
private: devMode,
unlisted: devMode
}))
.use(permalinks({
relative: false
}))
.use(collections({
gallery: 'assets/images/gallery/*.{jpg,png}',
updates: {
metadata: {
title: 'Updates',
header: 'Brief updates',
description: 'quick details about what is going on',
path: 'updates',
postTemplate: 'micro',
listClass: 'updates',
image: {
slug: 'updates.jpg',
source: 'https://unsplash.com/photos/happy-birthday-greeting-card-on-brown-floral-textile-Iu8lD0411sc',
creator: 'Elena Mozhvilo'
}
},
pattern: 'updates/**/*.html',
refer: false,
sortBy: 'pubdate',
reverse: true,
limit: 10
},
blog: {
pattern: 'blog/**/*.html',
sortBy: 'pubdate',
reverse: true,
metadata: {
title: 'Blog',
header: 'All blog posts',
description: 'where I share my thoughts, ideas and general musings',
index: true,
path: 'blog',
postTemplate: 'long',
listClass: 'blog-index',
widgets: {
tags: {
position: 'sidebar'
}
},
image: {
slug: 'blog.jpg',
source: 'https://unsplash.com/photos/brown-and-green-square-box-mQPHWfsS4yY',
creator: 'Mitul Gajera'
},
features: {
sidebar: true
}
}
}
}))
.use(blog({
dev: devMode
}))
.use(gallery({
galleryMetadata
}))
.use(rss({
url: melindreamakes.metadata.siteurl,
title: melindreamakes.metadata.sitename,
description: melindreamakes.metadata.description,
copyright: melindreamakes.metadata.copyright
}))
.use(presence)
.use(breadcrumbs)
.use(bodyClasses)
.use(check)
.use(handlebarsDiscoverer({
directories: {
helpers: 'templates/helpers',
partials: 'templates/partials'
}
}))
.use(toc())
// Put the HTML fragments from the step above
// into our template, using the Frontmatter
// properties as template variables.
.use(layouts({
pattern: '**/*.html',
directory: 'templates'
}))
.use(sitemap({
hostname: melindreamakes.metadata.siteurl,
omitIndex: true
}))
.use(check)
.use(github)
// .use(webfinger(melindreamakes.metadata.webfinger))
// And tell Metalsmith to fire it all off.
.build((err) => { // build process
if (err) { throw err; } // error handling is required
console.log(`Build success in ${((performance.now() - t1) / 1000).toFixed(1)}s`);
});