Repository navigation
Expand file tree
/
Copy patheleventy.config.js
More file actions
42 lines (36 loc) · 1.59 KB
/
Copy patheleventy.config.js
File metadata and controls
42 lines (36 loc) · 1.59 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
import markdownIt from "markdown-it";
import markdownItAnchor from "markdown-it-anchor";
import { DateTime } from "luxon";
const TIME_ZONE = "America/New_York";
export default async function (eleventyConfig) {
eleventyConfig.setOutputDirectory("out");
// Eleventy doesn't need to touch these
eleventyConfig.addPassthroughCopy("css");
eleventyConfig.addPassthroughCopy("js");
eleventyConfig.addPassthroughCopy("images");
eleventyConfig.addPassthroughCopy("**/*.sh");
// I want to link to different sections
eleventyConfig.setLibrary("md", markdownIt({html: true, linkify: true}).use(markdownItAnchor, {level: [2, 3, 4]}));
// Fixes date parsing to use the correct time zone (this is horrible)
eleventyConfig.addDateParsing(function(dateValue) {
let localDate;
if(dateValue instanceof Date) {
localDate = DateTime.fromJSDate(dateValue, {zone: "utc" }).setZone(TIME_ZONE, { keepLocalTime: true });
} else if(typeof dateValue == "string") {
localDate = DateTime.fromISO(dateValue, { zone: TIME_ZONE });
}
if (localDate?.isValid === false) {
throw new Error(`Invalid \`date\` value (${dateValue}) is invalid for ${this.page.inputPath}: ${localDate.invalidReason}`);
}
return localDate;
});
eleventyConfig.addFilter("dateOnly", async function (dateVal, locale = "en-us") {
var date = new Date(dateVal);
const options = { year: "numeric", month: "short", day: "numeric" };
return date.toLocaleDateString(locale, options);
});
eleventyConfig.setFrontMatterParsingOptions({
excerpt: true,
excerpt_separator: "<!-- excerpt -->",
});
}