Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix sitemap #16026

Merged
merged 2 commits into from Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>