Merge pull request #22 from mathiasbynens/add-sitemap

Add sitemap.xml
This commit is contained in:
Zach Leatherman 2018-09-25 21:10:45 -05:00 committed by GitHub
commit 879355af72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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"); 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 // only content in the `posts/` directory
eleventyConfig.addCollection("posts", function(collection) { eleventyConfig.addCollection("posts", function(collection) {
return collection.getAllSorted().filter(function(item) { return collection.getAllSorted().filter(function(item) {

1
404.md
View File

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

View File

@ -1,5 +1,6 @@
--- ---
permalink: feed/feed.xml permalink: feed/feed.xml
excludeFromSitemap: true
--- ---
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"> <feed xmlns="http://www.w3.org/2005/Atom">

View File

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