forked from jmschrack/Dark-Portfolio-Template-11ty
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eleventy.js
More file actions
74 lines (65 loc) · 2.07 KB
/
Copy path.eleventy.js
File metadata and controls
74 lines (65 loc) · 2.07 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
const pluginRss = require("@11ty/eleventy-plugin-rss");
const htmlmin = require("html-minifier-terser");
module.exports = function (eleventyConfig) {
// Static passthrough
eleventyConfig.addPassthroughCopy("css");
eleventyConfig.addPassthroughCopy("js");
eleventyConfig.addPassthroughCopy("img");
eleventyConfig.addPassthroughCopy("files");
eleventyConfig.addPassthroughCopy("fonts"); // Added fonts directory
// Watch targets
eleventyConfig.addWatchTarget("css");
eleventyConfig.addWatchTarget("js");
eleventyConfig.addWatchTarget("img/showreel");
// RSS plugin + filters
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addFilter("absoluteUrl", (url, base) =>
pluginRss.absoluteUrl(url, base)
);
eleventyConfig.addFilter("htmlDateString", (dateObj) => {
try {
return new Date(dateObj).toISOString();
} catch {
return "";
}
});
eleventyConfig.addFilter("readableDate", (dateObj) => {
try {
const d = new Date(dateObj);
return new Intl.DateTimeFormat("en-GB", {
day: "2-digit",
month: "short",
year: "numeric",
}).format(d);
} catch {
return "";
}
});
// tagList collection
eleventyConfig.addCollection("tagList", (collectionsApi) => {
const set = new Set();
collectionsApi.getAll().forEach((item) => {
(item.data.tags || []).forEach((t) => set.add(t));
});
return [...set];
});
// HTML Minifier Transform (Only runs in production)
eleventyConfig.addTransform("htmlmin", function (content, outputPath) {
if (process.env.ELEVENTY_ENV === "production" && outputPath && outputPath.endsWith(".html")) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true
});
return minified;
}
return content;
});
// Eleventy config
return {
dir: { input: ".", includes: "_includes", data: "_data", output: "_site" },
serverOptions: { liveReload: false, domDiff: false, port: 8087 },
};
};