File tree Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ const yaml = require("js-yaml");
15
15
16
16
const { imageShortcode, imageWithClassShortcode } = require ( './config' ) ;
17
17
18
+ const siteData = yaml . load ( fs . readFileSync ( './_data/site.yaml' , 'utf8' ) ) ;
19
+
18
20
module . exports = function ( config ) {
19
21
// Set pathPrefix for site
20
22
let pathPrefix = '/' ;
@@ -73,6 +75,12 @@ module.exports = function (config) {
73
75
config . addFilter ( 'contrastRatio' , contrastRatio ) ;
74
76
config . addFilter ( 'humanReadableContrastRatio' , humanReadableContrastRatio ) ;
75
77
78
+ // Create absolute urls
79
+ config . addFilter ( 'asAbsoluteUrl' , ( relativeUrl ) => {
80
+ const host = siteData . host ;
81
+ return new URL ( relativeUrl , host ) . href ;
82
+ } ) ;
83
+
76
84
// Create an array of all tags
77
85
config . addCollection ( 'tagList' , function ( collection ) {
78
86
let tagSet = new Set ( ) ;
Original file line number Diff line number Diff line change @@ -4,13 +4,17 @@ eleventyExcludeFromCollections: true
4
4
---
5
5
<?xml version =" 1.0" encoding =" utf-8" ?>
6
6
<urlset xmlns =" http://www.sitemaps.org/schemas/sitemap/0.9" >
7
- {%- for page in collections .all %}
8
- {% if page .url %}
9
- {% set absoluteUrl %} {{ page .url | url | absoluteUrl }} {% endset %}
10
- <url >
11
- <loc >{{ absoluteUrl }} </loc >
12
- <lastmod >{{ page .date | htmlDateString }} </lastmod >
13
- </url >
14
- {% endif %}
15
- {%- endfor %}
7
+ {%- for page in collections .all %}
8
+ {%- if page .url %}
9
+ {%- set renderedUrl %} {{ page .url | url }} {%- endset %}
10
+ <url >
11
+ {%- if env .production %}
12
+ <loc >{{ renderedUrl | asAbsoluteUrl }} </loc >
13
+ {%- else %}
14
+ <loc >{{ renderedUrl }} </loc >
15
+ {%- endif %}
16
+ <lastmod >{{ page .date | htmlDateString }} </lastmod >
17
+ </url >
18
+ {%- endif %}
19
+ {%- endfor %}
16
20
</urlset >
You can’t perform that action at this time.
0 commit comments