@@ -17,12 +17,27 @@ const {
1717} = require ( '@vidhill/fortawesome-brands-11ty-shortcode' ) ;
1818
1919
20- module . exports = function ( eleventyConfig ) {
20+ const media_filetypes = "jpg,jpeg,JPG,png,gif,svg,avif" ;
21+
22+ async function img_responsive ( src , alt , sizes = "100vw, 720, 820, 940, 1140, 1280" , class_names = "img-responsive" ) {
23+ let metadata = await fetch_image ( src ) ;
24+ let imageAttributes = {
25+ alt,
26+ sizes,
27+ class : class_names ,
28+ loading : "lazy" ,
29+ decoding : "async" ,
30+ } ;
31+
32+ return Image . generateHTML ( metadata , imageAttributes ) ;
33+ }
34+
35+ module . exports = function ( eleventyConfig ) {
2136 // Configure markdown parser
22- const markdownLib = markdownIt ( { html : true , typographer : true } ) ;
37+ const markdownLib = markdownIt ( { html : true , typographer : true } ) ;
2338 markdownLib . use ( markdownItAnchor ) ;
2439 markdownLib . use ( markdownItAttrs ) ;
25-
40+
2641 eleventyConfig . setLibrary ( "md" , markdownLib ) ;
2742 eleventyConfig . addPlugin ( fortawesomeBrandsPlugin ) ;
2843 eleventyConfig . addPlugin ( syntaxHighlight ) ;
@@ -34,11 +49,11 @@ module.exports = function(eleventyConfig) {
3449 eleventyConfig . addPassthroughCopy ( "assets" ) ;
3550 eleventyConfig . addPassthroughCopy ( "dist" ) ;
3651 eleventyConfig . addPassthroughCopy ( "favicon.png" ) ;
37- eleventyConfig . addPassthroughCopy ( "galleries/**/*.{jpg,jpeg,JPG,png,gif,svg}" ) ;
52+ eleventyConfig . addPassthroughCopy ( "galleries/**/*." + media_filetypes ) ;
3853 eleventyConfig . addPassthroughCopy ( "google5458abc1104b04dd.html" ) ;
39- eleventyConfig . addPassthroughCopy ( { "htaccess" : ".htaccess" } ) ;
40- eleventyConfig . addPassthroughCopy ( { "content" : "." } , {
41- filter : [ "**/*.{jpg,jpeg,JPG,png,gif,svg}" ] ,
54+ eleventyConfig . addPassthroughCopy ( { "htaccess" : ".htaccess" } ) ;
55+ eleventyConfig . addPassthroughCopy ( { "content" : "." } , {
56+ filter : [ "**/*." + + media_filetypes ] ,
4257 rename : function ( path ) {
4358 return path . replace ( "content/" , "" ) ;
4459 }
@@ -47,7 +62,7 @@ module.exports = function(eleventyConfig) {
4762 eleventyConfig . addWatchTarget ( "src/**/*" ) ;
4863 let $collectionApi = null ;
4964
50- eleventyConfig . addCollection ( "posts" , function ( collectionApi ) {
65+ eleventyConfig . addCollection ( "posts" , function ( collectionApi ) {
5166 $collectionApi = collectionApi ;
5267 return collectionApi . getFilteredByGlob ( "_posts/*.md" ) ;
5368 } ) ;
@@ -56,55 +71,12 @@ module.exports = function(eleventyConfig) {
5671 dynamicPartials : false ,
5772 } ) ;
5873
59- eleventyConfig . addFilter ( "cssmin" , function ( code ) {
74+ eleventyConfig . addFilter ( "cssmin" , function ( code ) {
6075 return new CleanCSS ( { } ) . minify ( code ) . styles ;
6176 } ) ;
6277
63- eleventyConfig . addShortcode ( "image" , async function ( src , alt , sizes ) {
64- let metadata = await fetch_image ( src ) ;
65-
66- let imageAttributes = {
67- alt,
68- sizes,
69- loading : "lazy" ,
70- decoding : "async" ,
71- } ;
72-
73- // You bet we throw an error on a missing alt (alt="" works okay)
74- return Image . generateHTML ( metadata , imageAttributes ) ;
75- } ) ;
76-
77- eleventyConfig . addShortcode ( "img_responsive" , async function ( src , alt , sizes = "100vw, 720, 820, 940, 1140, 1280" ) {
78- let metadata = await fetch_image ( src ) ;
79- let imageAttributes = {
80- alt,
81- sizes,
82- class : "img-responsive" ,
83- loading : "lazy" ,
84- decoding : "async" ,
85- } ;
86-
87- return Image . generateHTML ( metadata , imageAttributes ) ;
88- } ) ;
89-
90- eleventyConfig . addShortcode ( "image_with_class" , async function ( src , alt , sizes , class_names ) {
91- let metadata = await fetch_image ( src ) ;
92-
93- if ( sizes == undefined || sizes == "_" ) {
94- sizes = "720, 940, 1140, 1280, 2048" ;
95- }
96-
97- let imageAttributes = {
98- alt,
99- sizes,
100- class : class_names ,
101- loading : "lazy" ,
102- decoding : "async" ,
103- } ;
104-
105- // You bet we throw an error on a missing alt (alt="" works okay)
106- return Image . generateHTML ( metadata , imageAttributes ) ;
107- } ) ;
78+ eleventyConfig . addShortcode ( "image" , img_responsive ) ;
79+ eleventyConfig . addShortcode ( "img_responsive" , img_responsive ) ;
10880
10981 // Thumbnails
11082 eleventyConfig . addShortcode ( "thumbnail_for_post" , thumbnails . thumbnail_for_post ) ;
@@ -122,15 +94,15 @@ module.exports = function(eleventyConfig) {
12294 } ) ;
12395
12496 // Liquid filter to convert a date to a string
125- eleventyConfig . addLiquidFilter ( "to_utc_string" , date => date . toUTCString ( ) ) ;
97+ eleventyConfig . addLiquidFilter ( "to_utc_string" , date => date . toUTCString ( ) ) ;
12698
12799 // Liquid filter for long date string
128- eleventyConfig . addLiquidFilter ( "date_to_long_string" , function ( date ) {
100+ eleventyConfig . addLiquidFilter ( "date_to_long_string" , function ( date ) {
129101 return date . toLocaleDateString ( "en-GB" , { weekday : 'long' , year : 'numeric' , month : 'long' , day : 'numeric' } ) ;
130102 } ) ;
131103
132104 // Universal filter for jsonify
133- eleventyConfig . addFilter ( "jsonify" , JSON . stringify ) ;
105+ eleventyConfig . addFilter ( "jsonify" , JSON . stringify ) ;
134106
135107 eleventyConfig . addFilter ( "with_explicit_date" , items => items . filter ( item => "date" in item . data ) ) ;
136108
@@ -140,14 +112,14 @@ module.exports = function(eleventyConfig) {
140112
141113 // Read the menu data from _config.yml and add it to the global data
142114 eleventyConfig . addGlobalData ( "menu" , ( ) => getDataFromConfigYaml ( "menu" ) ) ;
143- eleventyConfig . addGlobalData ( "site_title" , ( ) => getDataFromConfigYaml ( "title" ) ) ;
144- eleventyConfig . addGlobalData ( "site_tagline" , ( ) => getDataFromConfigYaml ( "tagline" ) ) ;
145- eleventyConfig . addGlobalData ( "production_url" , ( ) => getDataFromConfigYaml ( "production_url" ) ) ;
146- eleventyConfig . addGlobalData ( "JB" , ( ) => getDataFromConfigYaml ( "JB" ) ) ;
147- eleventyConfig . addGlobalData ( "author" , ( ) => getDataFromConfigYaml ( "author" ) ) ;
148- eleventyConfig . addGlobalData ( "now" , ( ) => new Date ( ) ) ;
149-
150- eleventyConfig . addNunjucksFilter ( "date" , function ( date , format ) {
115+ eleventyConfig . addGlobalData ( "site_title" , ( ) => getDataFromConfigYaml ( "title" ) ) ;
116+ eleventyConfig . addGlobalData ( "site_tagline" , ( ) => getDataFromConfigYaml ( "tagline" ) ) ;
117+ eleventyConfig . addGlobalData ( "production_url" , ( ) => getDataFromConfigYaml ( "production_url" ) ) ;
118+ eleventyConfig . addGlobalData ( "JB" , ( ) => getDataFromConfigYaml ( "JB" ) ) ;
119+ eleventyConfig . addGlobalData ( "author" , ( ) => getDataFromConfigYaml ( "author" ) ) ;
120+ eleventyConfig . addGlobalData ( "now" , ( ) => new Date ( ) ) ;
121+
122+ eleventyConfig . addNunjucksFilter ( "date" , function ( date , format ) {
151123 return moment ( date ) . format ( format ) ;
152124 } ) ;
153125
0 commit comments