Add sitemap.xml

master
Mathias Bynens 2018-09-24 15:09:15 -04:00
parent 4a517aecc1
commit 096ff9f3de
No known key found for this signature in database
GPG Key ID: B6A1C4401A39330B
5 changed files with 26 additions and 2 deletions

View File

@ -12,6 +12,11 @@ module.exports = function(eleventyConfig) {
return DateTime.fromJSDate(dateObj).toFormat("dd LLL yyyy");
});
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
eleventyConfig.addFilter('htmlDateString', (dateObj) => {
return DateTime.fromJSDate(dateObj).toFormat('yyyy-LL-dd');
});
// only content in the `posts/` directory
eleventyConfig.addCollection("posts", function(collection) {
return collection.getAllSorted().filter(function(item) {

1
404.md
View File

@ -1,6 +1,7 @@
---
layout: layouts/home.njk
permalink: 404.html
excludeFromSitemap: true
---
# Content not found.

View File

@ -1,5 +1,6 @@
---
permalink: feed/feed.xml
excludeFromSitemap: true
---
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
@ -23,4 +24,4 @@ permalink: feed/feed.xml
<content type="html">{{ post.templateContent | htmlToAbsoluteUrls(absolutePostUrl) }}</content>
</entry>
{%- endfor %}
</feed>
</feed>

View File

@ -1,5 +1,6 @@
---
permalink: feed/.htaccess
excludeFromSitemap: true
---
# For Apache, to show `{{ metadata.feed.filename }}` when browsing to directory /feed/ (hide the file!)
DirectoryIndex {{ metadata.feed.filename }}
DirectoryIndex {{ metadata.feed.filename }}

16
sitemap.xml.njk Normal file
View File

@ -0,0 +1,16 @@
---
permalink: /sitemap.xml
excludeFromSitemap: true
---
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{%- for page in collections.all %}
{%- if not page.data.excludeFromSitemap %}
{% set absoluteUrl %}{{ page.url | url | absoluteUrl(metadata.url) }}{% endset %}
<url>
<loc>{{ absoluteUrl }}</loc>
<lastmod>{{ page.date | htmlDateString }}</lastmod>
</url>
{%- endif %}
{%- endfor %}
</urlset>