Skip to content

Instantly share code, notes, and snippets.

@magician11
Created September 10, 2023 20:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magician11/bdf9dcf68a0e0b6a1f3a7932c6c46bf1 to your computer and use it in GitHub Desktop.
Save magician11/bdf9dcf68a0e0b6a1f3a7932c6c46bf1 to your computer and use it in GitHub Desktop.
sitemap.xml and robots.txt for 11ty (Eleventy)
---
eleventyExcludeFromCollections: true
eleventyComputed:
permalink: "{{ site.robots }}"
---
Sitemap: {{ site.baseUrl + site.siteMap }}
User-agent: *
Disallow:
{
"baseUrl": "https://example.com",
"robots": "/robots.txt",
"siteMap": "/sitemap.xml"
}
---
permalink: /sitemap.xml
eleventyExcludeFromCollections: true
---
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for page in collections.all %}
<url>
<loc>{{ site.baseUrl }}{{ page.url | url }}</loc>
<lastmod>{{ page.date.toISOString() }}</lastmod>
</url>
{% endfor %}
</urlset>
@magician11
Copy link
Author

Place site.json in the _data directory, and place robots.txt.njk and sitemap.njk at the root of the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment