11import { DateTime } from "luxon" ;
2- import fs from 'fs' ;
3- import path from ' path' ;
4- import { fileURLToPath } from ' url' ;
2+ import fs from "fs" ;
3+ import path from " path" ;
4+ import { fileURLToPath } from " url" ;
55
66const __filename = fileURLToPath ( import . meta. url ) ;
77const __dirname = path . dirname ( __filename ) ;
88
9- /** @param {import("@11ty/eleventy").UserConfig } eleventyConfig */
10- export default function ( eleventyConfig ) {
9+ export default function ( eleventyConfig ) {
1110 eleventyConfig . addFilter ( "readableDate" , ( dateObj , format , zone ) => {
1211 // Formatting tokens for Luxon: https://moment.github.io/luxon/#/formatting?id=table-of-tokens
13- return DateTime . fromJSDate ( dateObj , { zone : zone || "utc" } ) . toFormat ( format || "dd LLLL yyyy" ) ;
12+ return DateTime . fromJSDate ( dateObj , { zone : zone || "utc" } ) . toFormat (
13+ format || "dd LLLL yyyy" ,
14+ ) ;
1415 } ) ;
1516
1617 eleventyConfig . addFilter ( "htmlDateString" , ( dateObj ) => {
1718 // dateObj input: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
18- return DateTime . fromJSDate ( dateObj , { zone : "utc" } ) . toFormat ( ' yyyy-LL-dd' ) ;
19+ return DateTime . fromJSDate ( dateObj , { zone : "utc" } ) . toFormat ( " yyyy-LL-dd" ) ;
1920 } ) ;
2021
2122 // Get the first `n` elements of a collection.
2223 eleventyConfig . addFilter ( "head" , ( array , n ) => {
23- if ( ! Array . isArray ( array ) || array . length === 0 ) {
24+ if ( ! Array . isArray ( array ) || array . length === 0 ) {
2425 return [ ] ;
2526 }
26- if ( n < 0 ) {
27+ if ( n < 0 ) {
2728 return array . slice ( n ) ;
2829 }
2930
@@ -36,32 +37,38 @@ export default function(eleventyConfig) {
3637 } ) ;
3738
3839 // Return the keys used in an object
39- eleventyConfig . addFilter ( "getKeys" , target => {
40+ eleventyConfig . addFilter ( "getKeys" , ( target ) => {
4041 return Object . keys ( target ) ;
4142 } ) ;
4243
4344 eleventyConfig . addFilter ( "filterTagList" , function filterTagList ( tags ) {
44- return ( tags || [ ] ) . filter ( tag => [ "all" , "posts" ] . indexOf ( tag ) === - 1 ) ;
45+ return ( tags || [ ] ) . filter ( ( tag ) => [ "all" , "posts" ] . indexOf ( tag ) === - 1 ) ;
4546 } ) ;
4647
47- eleventyConfig . addFilter ( "sortAlphabetically" , strings =>
48- ( strings || [ ] ) . sort ( ( b , a ) => b . localeCompare ( a ) )
48+ eleventyConfig . addFilter ( "sortAlphabetically" , ( strings ) =>
49+ ( strings || [ ] ) . sort ( ( b , a ) => b . localeCompare ( a ) ) ,
4950 ) ;
5051
51- eleventyConfig . addFilter ( "inlineSvg" , function ( iconName ) {
52- if ( ! iconName ) return '' ;
53-
54- const iconPath = path . join ( __dirname , '..' , '_includes' , 'icons' , `${ iconName } .svg` ) ;
55-
52+ eleventyConfig . addFilter ( "inlineSvg" , function ( iconName ) {
53+ if ( ! iconName ) return "" ;
54+
55+ const iconPath = path . join (
56+ __dirname ,
57+ ".." ,
58+ "_includes" ,
59+ "icons" ,
60+ `${ iconName } .svg` ,
61+ ) ;
62+
5663 try {
5764 if ( fs . existsSync ( iconPath ) ) {
58- const svg = fs . readFileSync ( iconPath , ' utf8' ) ;
65+ const svg = fs . readFileSync ( iconPath , " utf8" ) ;
5966 return svg ;
6067 }
61- return '' ;
68+ return "" ;
6269 } catch ( err ) {
6370 console . warn ( `Could not load SVG icon: ${ iconName } ` , err ) ;
64- return '' ;
71+ return "" ;
6572 }
6673 } ) ;
6774}
0 commit comments