Skip to content

Commit

Permalink
Add sitemap.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasbynens committed Sep 24, 2018
1 parent 4a517ae commit 096ff9f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions 404.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
layout: layouts/home.njk
permalink: 404.html
excludeFromSitemap: true
---
# Content not found.

Expand Down
3 changes: 2 additions & 1 deletion feed/feed.njk
Original file line number Diff line number Diff line change
@@ -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">
Expand All @@ -23,4 +24,4 @@ permalink: feed/feed.xml
<content type="html">{{ post.templateContent | htmlToAbsoluteUrls(absolutePostUrl) }}</content>
</entry>
{%- endfor %}
</feed>
</feed>
3 changes: 2 additions & 1 deletion feed/htaccess.njk
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 0 deletions sitemap.xml.njk
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 096ff9f

Please sign in to comment.