Generating Sitemap Files for Jekyll | Generated by AI
A sitemap.xml is an XML file that tells search engines like Google and Bing about the pages on your website. It helps crawlers discover and index your site’s structure more efficiently. For a Jekyll blog, this means search engines can find all your posts, pages, and translations (like your index-zh.html, index-fr.html, etc.) even if they’re not linked everywhere.
What a Sitemap Does
- Lists all important URLs of your site.
- Provides metadata such as the last modified date (
<lastmod>), change frequency (<changefreq>), and priority (<priority>). - Improves SEO by ensuring crawlers don’t miss pages.
How to Generate for Jekyll
You have a couple of approaches:
1. Use the jekyll-sitemap plugin (recommended)
-
In your Jekyll project’s
Gemfile, add:gem 'jekyll-sitemap' -
In your
_config.yml, add:plugins: - jekyll-sitemap(If you’re on GitHub Pages,
jekyll-sitemapis already whitelisted, so it works directly.) -
When you build (
jekyll buildor viamakeif you have it set up), Jekyll will automatically generate asitemap.xmlin your_site/folder.
2. Manually create a sitemap template
If you prefer more control:
- Create a file at the project root:
/sitemap.xml. -
Add this Liquid template:
--- layout: nil --- <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> {% for page in site.pages %} {% if page.sitemap != false %} <url> <loc>{{ site.url }}{{ page.url | replace:'index.html','' }}</loc> <lastmod>{{ page.date | date_to_xmlschema }}</lastmod> </url> {% endif %} {% endfor %} {% for post in site.posts %} <url> <loc>{{ site.url }}{{ post.url }}</loc> <lastmod>{{ post.date | date_to_xmlschema }}</lastmod> </url> {% endfor %} </urlset> - Make sure your
_config.ymlhasurl: "https://yourdomain.com"so links generate correctly.
3. Verify
- After building, check
_site/sitemap.xml. - Submit it to Google Search Console for better indexing.
👉 Since you already have _config.yml and _plugins/, the easiest is to just enable jekyll-sitemap. That way, you won’t need to maintain the XML manually.
Do you want me to draft the exact _config.yml addition for your repo (based on your current files), so you can paste it directly?