-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
84 lines (72 loc) · 2.55 KB
/
.eleventy.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
import eleventyNavigationPlugin from "@11ty/eleventy-navigation"
import postcss from "postcss"
import postcssImport from "postcss-import"
import postcssMinify from "postcss-minify"
import { minify } from "terser"
export default function (eleventyConfig) {
// Filters --------------------------
eleventyConfig.addFilter("sortCollectionByFilename", (c) => {
return c.sort((a, b) => {
const aNum = parseInt(a.fileSlug.split("-")[0])
const bNum = parseInt(b.fileSlug.split("-")[0])
return aNum - bNum
})
})
eleventyConfig.addFilter("externalLink", (url) => {
return url.match(/\/*/)[0] != "/"
})
// Plugins --------------------------
eleventyConfig.addPlugin(eleventyNavigationPlugin)
// JS processing --------------------
eleventyConfig.addTemplateFormats("js")
eleventyConfig.addExtension("js", {
compile: async (content, path) => {
return async () => {
let output = await minify(content, {})
return output.code
}
},
compileOptions: {
permalink: function (contents, inputPath) {
// NOTE: is there a better way to change the extension?
inputPath = inputPath.replace("_source/theme/js/", "/assets/")
inputPath = inputPath.replace(".js", ".min.js")
return inputPath
}
}
})
// CSS processing -------------------
eleventyConfig.addTemplateFormats("css")
eleventyConfig.addExtension("css", {
outputFileExtension: "min.css",
compile: async (content, path) => {
if (path !== "./_source/theme/css/_core.css") {
return
}
return async () => {
let output = await postcss([
postcssImport,
postcssMinify
]).process(content, {
from: path
})
return output.css
}
}
})
// Short codes ----------------------
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`)
// Passthrough ----------------------
eleventyConfig.addPassthroughCopy({ "./_source/theme/assets": "/assets" })
// 11ty Settings --------------------
return {
dir: {
input: "_source",
data: "_data",
includes: "/theme/_includes",
layouts: "/theme/_layouts"
},
dataTemplateEngine: "njk",
markdownTemplateEngine: "njk"
}
}