Skip to content

Commit

Permalink
improve sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
hjonin committed Sep 15, 2023
1 parent a671cbc commit e6cbd47
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion content/sitemap/sitemap.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: layouts/page.njk
---
{# List every content page in the project #}
<ul data-pagefind-ignore>
{% for entry in collections.all %}
{% for entry in collections.allSortedByPathAsc %}
{% if entry.url %}
<li><a href="{{ entry.url }}"><code>{{ entry.url }}</code></a></li>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion content/sitemap/sitemap.xml.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ eleventyExcludeFromCollections: true
---
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
{% for page in collections.all %}
{% for page in collections.allSortedByPathAsc %}
{% if page.url %}
{% set absoluteUrl %}{{ page.url | htmlBaseUrl(metadata.url) }}{% endset %}
<url>
Expand Down
6 changes: 6 additions & 0 deletions eleventy.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ module.exports = function (eleventyConfig) {
.concat(collectionApi.getFilteredByTags("bluehats_posts"));
});

eleventyConfig.addCollection("allSortedByPathAsc", function(collectionApi) {
return collectionApi.getAll().sort(function(a, b) {
return a.inputPath.localeCompare(b.inputPath);
});
});

// Filters
eleventyConfig.addFilter("jsDateObject", function jsDateObject(dateStr, format, zone) {
return DateTime.fromFormat(dateStr, format || "yyyy-LL-dd", {zone: zone || "utc"}).toJSDate();
Expand Down

0 comments on commit e6cbd47

Please sign in to comment.