-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
105 lines (94 loc) · 3.22 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { EleventyHtmlBasePlugin, InputPathToUrlTransformPlugin } from "@11ty/eleventy";
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
import { feedPlugin } from "@11ty/eleventy-plugin-rss";
import CleanCSS from "clean-css";
import { DateTime } from "luxon";
import fs from "node:fs";
import { tufteMdWrapper } from "./util/tufteMdWrapper.js";
export default function (eleventyConfig) {
// Copy `src/assets` to `_site/assets`
eleventyConfig.addPassthroughCopy("src/assets");
// Copy some more files to `_site`
eleventyConfig.addPassthroughCopy("src/CNAME");
eleventyConfig.addPassthroughCopy("src/robots.txt");
eleventyConfig.addPassthroughCopy("src/manifest.json");
// Asset Watch Targets
eleventyConfig.addWatchTarget("./src/assets");
/* Markdown Configuration */
eleventyConfig.setLibrary("md", tufteMdWrapper);
eleventyConfig.addFilter("markdown", tufteMdWrapper.render);
eleventyConfig.addFilter("markdownInline", tufteMdWrapper.renderInline);
// Date stuff
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`); // useful for copyright
eleventyConfig.addFilter("postDate", (dateObj) => {
if (typeof dateObj === "string") {
dateObj = DateTime.fromISO(dateObj);
} else {
dateObj = DateTime.fromJSDate(dateObj);
}
return dateObj.toFormat("MMMM d, yyyy");
});
eleventyConfig.addFilter("lastModifiedDate", function (filepath) {
const stat = fs.statSync(filepath);
return stat.mtime.toISOString();
});
// Add wordCount filter
eleventyConfig.addFilter("wordCount", function (content) {
if (typeof content !== "string") {
return 0;
}
const words = content.split(/\s+/);
return words.length;
});
// CSS Minification
eleventyConfig.addFilter("cssmin", function (code) {
return new CleanCSS({}).minify(code).styles;
});
// RSS Feed
eleventyConfig.addPlugin(feedPlugin, {
type: "atom",
outputPath: "/feed.xml",
collection: {
name: "post", // Only posts, not recipes
limit: 10, // 0 for no limit
},
metadata: {
language: "en",
title: "Tyler's Technical Blog",
subtitle: "Notes on Machine Learning and related topics.",
base: "https://tylerromero.com/",
author: {
name: "Tyler Romero",
email: "[email protected]",
},
},
});
// Image Shortcode And Optimizations
eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
extensions: "html",
formats: ["webp", "auto"], // "auto" means use the original format
sharpOptions: {
animated: true, // Enable animated GIF and WebP support
},
widths: [300, 600, 900, "auto"], // mobile, tablet, desktop viewport widths, and original size
defaultAttributes: {
loading: "lazy",
decoding: "async",
sizes: "(max-width: 900px) 100vw, 900px",
class: "responsive-image",
},
urlPath: "/assets/img/",
outputDir: "_site/assets/img/",
});
// Plugins
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
eleventyConfig.addPlugin(InputPathToUrlTransformPlugin);
return {
// When a passthrough file is modified, rebuild the pages:
passthroughFileCopy: true,
dir: {
input: "src",
layouts: "_layouts",
},
};
}