mirror of
https://github.com/ckaczor/Blog.git
synced 2026-01-14 01:25:37 -05:00
Reformatting
This commit is contained in:
@@ -1,22 +1,26 @@
|
||||
import { DateTime } from "luxon";
|
||||
|
||||
export default function(eleventyConfig) {
|
||||
export default function (eleventyConfig) {
|
||||
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) => {
|
||||
// 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) {
|
||||
if (!Array.isArray(array) || array.length === 0) {
|
||||
return [];
|
||||
}
|
||||
if( n < 0 ) {
|
||||
if (n < 0) {
|
||||
return array.slice(n);
|
||||
}
|
||||
|
||||
@@ -29,12 +33,13 @@ export default function(eleventyConfig) {
|
||||
});
|
||||
|
||||
// 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) {
|
||||
return (tags || []).filter(tag => ["all", "posts"].indexOf(tag) === -1);
|
||||
return (tags || []).filter(
|
||||
(tag) => ["all", "posts"].indexOf(tag) === -1
|
||||
);
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user