diff --git a/docs/.eleventy.js b/docs/.eleventy.js index 49b6bbf0d5a..830ac693eb8 100644 --- a/docs/.eleventy.js +++ b/docs/.eleventy.js @@ -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, diff --git a/docs/src/static/robots.njk b/docs/src/static/robots.njk index 0810671e2ae..a6bf2474790 100644 --- a/docs/src/static/robots.njk +++ b/docs/src/static/robots.njk @@ -3,6 +3,5 @@ layout: false permalink: robots.txt eleventyExcludeFromCollections: true --- -Sitemap: {{ metadata.url }}/sitemap.xml User-agent: * Disallow: / diff --git a/docs/src/static/sitemap.njk b/docs/src/static/sitemap.njk index 3b02013f499..e92a4e56844 100644 --- a/docs/src/static/sitemap.njk +++ b/docs/src/static/sitemap.njk @@ -6,9 +6,9 @@ eleventyExcludeFromCollections: true {% for page in collections.all %} - {{ site.url }}{{ page.url | url | prettyURL }} + {{ ["https://", site.hostname, page.url | url | prettyURL] | join }} {{ page.date.toISOString() }} - {{ page.data.changeFreq or "monthly" }} + {{ page.data.changeFreq if page.data.changeFreq else "weekly" }} {% endfor %}