Commit 046f8a7 1 parent 7bbcbec commit 046f8a7 Copy full SHA for 046f8a7
File tree 3 files changed +21
-7
lines changed
3 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -517,9 +517,13 @@ module.exports = function (eleventyConfig) {
517
517
518
518
519
519
eleventyConfig . addFilter ( "dateToZulu" , function ( date ) {
520
- if ( ! date ) return "" ;
521
- return new Date ( date ) . toISOString ( "dd-MM-yyyyTHH:mm:ssZ" ) ;
520
+ try {
521
+ return new Date ( date ) . toISOString ( "dd-MM-yyyyTHH:mm:ssZ" ) ;
522
+ } catch {
523
+ return "" ;
524
+ }
522
525
} ) ;
526
+
523
527
eleventyConfig . addFilter ( "jsonify" , function ( variable ) {
524
528
return JSON . stringify ( variable ) || '""' ;
525
529
} ) ;
Original file line number Diff line number Diff line change 1
1
<
script src =
" https://fastly.jsdelivr.net/npm/[email protected] /build/global/luxon.min.js " ></
script >
2
2
<script defer >
3
- TIMESTAMP_FORMAT = " {{meta.timestampSettings.timestampFormat}}" ;
4
- document .querySelectorAll (' .human-date' ).forEach (function (el ) {
5
- el .innerHTML = luxon .DateTime .fromISO (el .getAttribute (' data-date' ) || el .innerText ).toFormat (TIMESTAMP_FORMAT );
6
- });
3
+ TIMESTAMP_FORMAT = " {{meta.timestampSettings.timestampFormat}}" ;
4
+ document .querySelectorAll (' .human-date' ).forEach (function (el ) {
5
+ date = el .getAttribute (' data-date' ) || el .innerText
6
+ parsed_date = luxon .DateTime .fromISO (date)
7
+ if (parsed_date .invalid != null ){
8
+ // Date cannot be parsed
9
+ parsed_date = luxon .DateTime .fromSQL (date)
10
+ }
11
+ if (parsed_date .invalid != null ){
12
+ // Date still cannot be parsed
13
+ parsed_date = luxon .DateTime .fromHTML (date)
14
+ }
15
+ el .innerHTML = parsed_date .toFormat (TIMESTAMP_FORMAT );
16
+ })
7
17
</script >
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ eleventyExcludeFromCollections: true
7
7
{% for page in collections .all %}
8
8
<url >
9
9
<loc >{{ meta .siteBaseUrl }}{{ page .url | url }} </loc >
10
- <lastmod >{{ page .date . toISOString () }} </lastmod >
10
+ <lastmod >{{ page .date | dateToZulu }} </lastmod >
11
11
</url >
12
12
{% endfor %}
13
13
</urlset >
You can’t perform that action at this time.
0 commit comments