Files
fedi-classifieds/_config/filters.js

65 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2026-04-29 21:12:19 -07:00
import { DateTime } from "luxon";
2026-04-29 08:30:52 -07:00
export default function(eleventyConfig) {
// Return the keys used in an object
eleventyConfig.addFilter("getKeys", target => {
return Object.keys(target);
});
/* */
eleventyConfig.addFilter("getTagline", tag => {
let tagline;
switch (tag) {
case "animals and the outdoors":
2026-04-29 21:12:19 -07:00
tagline = "touchin' grass";
2026-04-29 08:30:52 -07:00
break;
case "art and crafts":
2026-04-29 21:12:19 -07:00
tagline = "makin' stuff";
2026-04-29 08:30:52 -07:00
break;
case "beauty and health":
tagline = "lookin' good";
break;
2026-04-29 08:30:52 -07:00
case "food and drink":
tagline = "good eatin'";
break;
case "history and science":
2026-04-29 21:12:19 -07:00
tagline = "book learnin'"
2026-04-29 08:30:52 -07:00
break;
2026-04-29 21:12:19 -07:00
case "repair and diy":
2026-04-29 08:30:52 -07:00
tagline = "fixin' stuff";
break;
case "interpersonal and life":
2026-04-29 21:12:19 -07:00
tagline = "better livin'";
2026-04-29 08:30:52 -07:00
break;
case "technology":
tagline = "computer touchin'";
break;
2026-04-29 21:12:19 -07:00
case "writing editing and literature":
tagline = "wordsmithin'";
2026-04-29 08:30:52 -07:00
break;
};
return tagline;
});
2026-04-29 21:12:19 -07:00
/* For <time> elements */
eleventyConfig.addFilter("htmlDateString", (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat('yyyy-LL-dd');
});
/* Human-readable dates */
eleventyConfig.addFilter("readableDate", (dateObj, zone) => {
return DateTime.fromJSDate(dateObj, { zone: zone || "utc" })
.toLocaleString(DateTime.DATE_FULL);
});
2026-04-29 08:30:52 -07:00
/* Filter out structural tags */
eleventyConfig.addFilter("removeCoreTags", (tags) => {
return tags.filter(tag => ["all"].indexOf(tag) === -1);
});
/* What it says on the tin */
eleventyConfig.addFilter("sortAlphabetically", strings =>
(strings || []).sort((b, a) => b.localeCompare(a))
);
};