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 d9ea5a8 commit 129f7a0
Show file tree
Hide file tree
Showing 3 changed files with 9 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
7 changes: 7 additions & 0 deletions eleventy.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(pluginBundle);
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);

// Custom collections
eleventyConfig.addCollection("allSortedByPathAsc", function(collectionApi) {
return collectionApi.getAll().sort((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 129f7a0

Please sign in to comment.