Skip to content

Commit

Permalink
chore: fix sitemap (#16026)
Browse files Browse the repository at this point in the history
* chore: fix sitemap

* refactor conditions for generating sitemaps
  • Loading branch information
mdjermanovic committed Jun 21, 2022
1 parent 285fbc5 commit db387a8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
20 changes: 20 additions & 0 deletions docs/.eleventy.js
Expand Up @@ -407,6 +407,26 @@ module.exports = function(eleventyConfig) {
}
});

/*
* Generate the sitemap only in certain contexts to prevent unwanted discovery of sitemaps that
* contain URLs we'd prefer not to appear in search results (URLs in sitemaps are considered important).
* In particular, we don't want to deploy https://eslint.org/docs/head/sitemap.xml
* We want to generate the sitemap for:
* - Local previews
* - Netlify deploy previews
* - Netlify production deploy of the `latest` branch (https://eslint.org/docs/latest/sitemap.xml)
*
* Netlify always sets `CONTEXT` environment variable. If it isn't set, we assume this is a local build.
*/
if (
process.env.CONTEXT && // if this is a build on Netlify ...
process.env.CONTEXT !== "deploy-preview" && // ... and not for a deploy preview ...
process.env.BRANCH !== "latest" // .. and not of the `latest` branch ...
) {
eleventyConfig.ignores.add("src/static/sitemap.njk"); // ... then don't generate the sitemap.
}


return {
passthroughFileCopy: true,

Expand Down
1 change: 0 additions & 1 deletion docs/src/static/robots.njk
Expand Up @@ -3,6 +3,5 @@ layout: false
permalink: robots.txt
eleventyExcludeFromCollections: true
---
Sitemap: {{ metadata.url }}/sitemap.xml
User-agent: *
Disallow: /
4 changes: 2 additions & 2 deletions docs/src/static/sitemap.njk
Expand Up @@ -6,9 +6,9 @@ eleventyExcludeFromCollections: true
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for page in collections.all %}
<url>
<loc>{{ site.url }}{{ page.url | url | prettyURL }}</loc>
<loc>{{ ["https://", site.hostname, page.url | url | prettyURL] | join }}</loc>
<lastmod>{{ page.date.toISOString() }}</lastmod>
<changefreq>{{ page.data.changeFreq or &quot;monthly&quot; }}</changefreq>
<changefreq>{{ page.data.changeFreq if page.data.changeFreq else "weekly" }}</changefreq>
</url>
{% endfor %}
</urlset>

0 comments on commit db387a8

Please sign in to comment.