Formatting and cleanup

This commit is contained in:
2024-11-11 21:36:33 +00:00
parent 232599a7f8
commit 8adccc6f95
30 changed files with 142 additions and 117 deletions

View File

@@ -1,45 +1,33 @@
import { DateTime } from "luxon";
import { DateTime } from 'luxon';
import markdownIt from 'markdown-it';
export default function (eleventyConfig) {
eleventyConfig.addFilter("readableDate", (dateObj, format, zone) => {
eleventyConfig.addFilter('readableDate', (dateObj, format, zone) => {
// Formatting tokens for Luxon: https://moment.github.io/luxon/#/formatting?id=table-of-tokens
return DateTime.fromJSDate(dateObj, { zone: zone || "utc" }).toFormat(
format || "dd LLLL yyyy"
return DateTime.fromJSDate(dateObj, { zone: zone || 'utc' }).toFormat(
format || 'dd LLLL yyyy'
);
});
eleventyConfig.addFilter("htmlDateString", (dateObj) => {
eleventyConfig.addFilter('htmlDateString', (dateObj) => {
// dateObj input: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat(
"yyyy-LL-dd"
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat(
'yyyy-LL-dd'
);
});
// Get the first `n` elements of a collection.
eleventyConfig.addFilter("head", (array, n) => {
if (!Array.isArray(array) || array.length === 0) {
return [];
}
if (n < 0) {
return array.slice(n);
}
return array.slice(0, n);
});
// Return the smallest number argument
eleventyConfig.addFilter("min", (...numbers) => {
return Math.min.apply(null, numbers);
});
// Return the keys used in an object
eleventyConfig.addFilter("getKeys", (target) => {
eleventyConfig.addFilter('getKeys', (target) => {
return Object.keys(target);
});
eleventyConfig.addFilter("filterTagList", function filterTagList(tags) {
eleventyConfig.addFilter('filterTagList', function filterTagList(tags) {
return (tags || []).filter(
(tag) => ["all", "posts"].indexOf(tag) === -1
(tag) => ['all', 'posts'].indexOf(tag) === -1
);
});
eleventyConfig.addFilter('md', function (content = '') {
return markdownIt({ html: true }).render(content);
});
}