How to create sitemap.xml? #1854
Replies: 16 comments
-
|
Hi @rolandtoth. I’ve created one for my (yet un-launched) site. You can use the following template (this uses liquid, but the underlying idea will work regardless of template format): ---
permalink: /sitemap.xml
---
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{%- for item in collections.all %}
{%- unless item.data.ignore == true %}
<url>
<loc>https://example.com{{ item.url }}</loc>
<lastmod>{{ item.date | date: '%Y-%m-%d' }}</lastmod>
<changefreq>{{ item.data.changefreq }}</changefreq>
<priority>{{ item.data.priority }}</priority>
</url>
{%- endunless %}
{%- endfor %}
</urlset>You’ll need to create a collection (I’ve used {
"layout": "layouts/article",
"permalink": "{{ page.date | date: '%Y/%m' }}/{{ page.fileSlug }}.html",
"changefreq": "monthly",
"priority": "0.9"
}For single pages, or if you need to override the above in a particular instance, just set the same values in your frontmatter, like so: ---
title: 'My great page'
permalink: /path/to/index.html
changefreq: weekly
priority: 1
---
Hello, and welcome to my great page!I also allow pages to be excluded from the sitemap if they have the value Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
|
Thanks @paulrobertlloyd , this was really useful. I made some minor modifications (added my own filters and adjusted to nunjucks, plus added an xsl stylesheet): |
Beta Was this translation helpful? Give feedback.
-
|
Thanks, this looks really useful too! Possibly a good candidate for the tutorials section. |
Beta Was this translation helpful? Give feedback.
-
|
@rolandtoth I'm curious what your Why not do |
Beta Was this translation helpful? Give feedback.
-
|
It's a filter I created for nunjucks so that if the variable I apply on doesn't exist then it will try using alternative values. I tried using your suggestion but the build failed ("Template render error"). module.exports = function () {
for (arg of arguments) {
if (arg) {
return arg;
}
}
return false;
};It's not too sophisticated but so far so good. It accepts multiple values, eg. for the SEO description I use something like this: So if the frontmatter seo_description is not set, it will try other frontmatter data (excerpt and title) and outputs the first that has value. |
Beta Was this translation helpful? Give feedback.
-
|
Oops, I got my syntax wrong. What I wanted to suggest was this: For your case I'm pretty sure you could do: |
Beta Was this translation helpful? Give feedback.
-
|
@zachleat is I'd assumed that since collections group things together by tag, that a tag would be required for it to ever appear. The |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the "var1 or var2" syntax, it works. However, if you apply a filter on it, you need to put them in parenthesis, otherwise the filter will be applied to the last item only.
|
Beta Was this translation helpful? Give feedback.
-
|
Here’s how I did it for v8.dev: 11ty/eleventy-base-blog#22 (before I saw this thread) |
Beta Was this translation helpful? Give feedback.
-
|
@rolandtoth @paulrobertlloyd @mathiasbynens per 11ty/eleventy#253, if you're using pagination, are pages that are generated showing up in your sitemap? I found |
Beta Was this translation helpful? Give feedback.
-
|
Sorry, I don't have pagination in any project where I have sitemap :) Update: just added a sitemap and pages like /page-3/, /page-4/, etc are not included. |
Beta Was this translation helpful? Give feedback.
-
|
@edwardhorsford per your comment here #1853 (comment) it looks like no! I’ve filed #21 |
Beta Was this translation helpful? Give feedback.
-
|
@rolandtoth ah, you might have gotten bit by 11ty/eleventy#253? Can you follow along over there? |
Beta Was this translation helpful? Give feedback.
-
|
This repository is now using lodash style issue management for documentation requests. This means documentation issues will now be closed instead of leaving them open. View the documentation queue backlog here. Don’t forget to upvote the top comment with 👍! |
Beta Was this translation helpful? Give feedback.
-
|
@zachleat Where would you like to see this documented? I assume, in the docs folder of https://github.com/11ty/11ty.io ? |
Beta Was this translation helpful? Give feedback.
-
Additionally, pages generated dynamically such as tag pages also seem to be hit or miss when it comes to the sitemap. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Could you provide some hint on how to create a sitemap.xml automatically?
Beta Was this translation helpful? Give feedback.
All reactions