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
|
const eleventy = require('@11ty/eleventy')
const eleventysyntaxhighlight = require('@11ty/eleventy-plugin-syntaxhighlight')
const eleventyrss = require('@11ty/eleventy-plugin-rss')
const markdown = require('markdown-it')
const markdownattrs = require('markdown-it-attrs')
const markdownanchor = require('markdown-it-anchor')
const markdownfootnote = require('markdown-it-footnote')
const postcss = require('postcss')
const postcssenv = require('postcss-preset-env')
const babel = require("@babel/core");
const crypto = require('node:crypto')
const luxon = require('luxon')
const slugify = require('@sindresorhus/slugify')
module.exports = eleventyConfig => {
eleventyConfig.addPlugin(eleventy.EleventyRenderPlugin);
eleventyConfig.addPlugin(eleventysyntaxhighlight)
eleventyConfig.addPlugin(eleventyrss)
eleventyConfig.setLibrary('md', markdown({
html: true,
linkify: true,
typographer: true
}).use(markdownattrs)
.use(markdownanchor, {
permalink: markdownanchor.permalink.headerLink(),
slugify: s => slugify(s)
}).use(markdownfootnote))
eleventyConfig.addFilter('datefmt', date => luxon.DateTime.fromJSDate(date, { zone: 'utc' }).toFormat("dd LLL yyyy"))
eleventyConfig.addFilter("tojson", obj => JSON.stringify(obj))
eleventyConfig.addExtension("css", {
outputFileExtension: "css",
compileOptions: {
permalink: "raw"
},
compile: async(content, filename) =>
async data => {
const css = await postcss().use(
postcssenv({
stage: 3,
features: {
"nesting-rules": true
}
}))
.process(content, {
from: filename,
map: data.env.NODE_ENV == "develoment"
})
return css.css
}
})
eleventyConfig.setBrowserSyncConfig({
snippet: false,
});
eleventyConfig.addExtension("mjs", {
outputFileExtension: "js",
compileOptions: {
permalink: "raw"
},
compile: (content, filename) =>
async data => {
const js = await babel.transformAsync(content, {
presets: [
["@babel/preset-env", {
"targets": {
"esmodules": true,
},
bugfixes: true
}]
],
plugins: [
["transform-define", {
VERSION: `${data.env.CF_PAGES_BRANCH || "default"}-${data.env.CF_PAGES_COMMIT_SHA || crypto.randomUUID()}`
}]
],
sourceMaps: data.env.NODE_ENV == "develoment" ? "inline" : false,
sourceFileName: filename
})
return js.code
}
})
eleventyConfig.addPassthroughCopy('static/')
eleventyConfig.addPassthroughCopy('_headers')
eleventyConfig.addPassthroughCopy('_redirects')
eleventyConfig.addPassthroughCopy('favicon/')
eleventyConfig.addPassthroughCopy('favicon.ico')
return {
dir: {
input: 'src',
output: 'dist',
includes: 'includes',
data: 'data',
layouts: 'layouts'
},
dataTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
templateFormats: [
'html',
'md',
'njk',
'11ty.js',
'css',
'mjs'
]
}
}
|