You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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):
You’ll need to create a collection (I’ve used collections.all) that encompasses all the files you want in your sitemap (see the documentation on how to achieve this). You’ll also want to ensure pages have the appropriate priorities and change frequencies set. I do this by using directory specific data files, to save adding these values to every page I create. Here’s an example for all my article pages:
Reacted by Kyle Mitofsky, Nixinova, Adam DJ Brett, Matthew Booth, khoivan88, Ivanov Vadim, Ari Palo, Vasanth Sriram, Peter Thaleikis, Sandesh Bhusal and 8 more
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").
@zachleat is collections.all documented? I hadn't seen it. It's not mentioned on the collections page. It's used on the permalinks page though.
I'd assumed that since collections group things together by tag, that a tag would be required for it to ever appear. The collections.all method is great.
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.
<lastmod>{{ (item.data.premier.date or item.date) | dateDisplay("toISOString") }}</lastmod>
per 11ty/buildawesome#253, if you're using pagination, are pages that are generated showing up in your sitemap? I found collections.all was not listing all the pages.
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.
@zachleat Where would you like to see this documented?
I've played around with the tips here and have a working sitemap.xml (for my use case).
So I could open a PR if you tell me, where the file should go to.
per 11ty/buildawesome#253, if you're using pagination, are pages that are generated showing up in your sitemap? I found collections.all was not listing all the pages.
Additionally, pages generated dynamically such as tag pages also seem to be hit or miss when it comes to the sitemap.
Activity
paulrobertlloyd commentedon Sep 22, 2018
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):
You’ll need to create a collection (I’ve used
collections.all) that encompasses all the files you want in your sitemap (see the documentation on how to achieve this). You’ll also want to ensure pages have the appropriate priorities and change frequencies set. I do this by using directory specific data files, to save adding these values to every page I create. Here’s an example for all my article pages:{ "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:
I also allow pages to be excluded from the sitemap if they have the value
ignoreset totrue. For example, here’s my 404 page:Hope this helps!
rolandtoth commentedon Sep 22, 2018
Thanks @paulrobertlloyd ,
this was really useful. I made some minor modifications (added my own filters and adjusted to nunjucks, plus added an xsl stylesheet):
https://neptunbrigad.hu/sitemap.xml
edwardhorsford commentedon Sep 22, 2018
Thanks, this looks really useful too!
Possibly a good candidate for the tutorials section.
edwardhorsford commentedon Sep 22, 2018
@rolandtoth I'm curious what your
valueIfEmpty('foobar')filter is doing.Why not do
{{ item.data.changefreq | "monthly" }}?rolandtoth commentedon Sep 22, 2018
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").
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.
edwardhorsford commentedon Sep 22, 2018
Oops, I got my syntax wrong. What I wanted to suggest was this:
{{ item.data.changefreq or "monthly" }}For your case I'm pretty sure you could do:
{{ seo_description or excerpt or title}}edwardhorsford commentedon Sep 22, 2018
@zachleat is
collections.alldocumented? I hadn't seen it. It's not mentioned on the collections page. It's used on the permalinks page though.I'd assumed that since collections group things together by tag, that a tag would be required for it to ever appear. The
collections.allmethod is great.rolandtoth commentedon Sep 22, 2018
@edwardhorsford
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.
<lastmod>{{ (item.data.premier.date or item.date) | dateDisplay("toISOString") }}</lastmod>mathiasbynens commentedon Sep 24, 2018
Here’s how I did it for v8.dev: 11ty/eleventy-base-blog#22 (before I saw this thread)
edwardhorsford commentedon Sep 25, 2018
@rolandtoth @paulrobertlloyd @mathiasbynens
per 11ty/buildawesome#253, if you're using pagination, are pages that are generated showing up in your sitemap? I found
collections.allwas not listing all the pages.rolandtoth commentedon Sep 25, 2018
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.
zachleat commentedon Oct 5, 2018
@edwardhorsford per your comment here #1853 (comment) it looks like no! I’ve filed #21
zachleat commentedon Jan 8, 2019
@rolandtoth ah, you might have gotten bit by 11ty/buildawesome#253? Can you follow along over there?
zachleat commentedon Jan 8, 2019
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 👍!
Ryuno-Ki commentedon Apr 7, 2019
@zachleat Where would you like to see this documented?
I've played around with the tips here and have a working sitemap.xml (for my use case).
So I could open a PR if you tell me, where the file should go to.
I assume, in the docs folder of https://github.com/11ty/11ty.io ?
MaybeThisIsRu commentedon Jul 4, 2020
Additionally, pages generated dynamically such as tag pages also seem to be hit or miss when it comes to the sitemap.
Improve SEO and Sitemap
🔍 Improve SEO and Sitemap
🔍 Improve SEO and Sitemap