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 1 commit
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
14 changes: 14 additions & 0 deletions docs/.eleventy.js
Expand Up @@ -407,6 +407,20 @@ 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
*/
if (!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we distribute the “not” here? I’m finding this condition a bit difficult to understand in its current form.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've refactored this a bit now, please check if the new version looks easier to reason about.

process.env.BRANCH === "latest" || // https://eslint.org/docs/latest/sitemap.xml
process.env.CONTEXT === "deploy-preview" || // deploy previews
!process.env.CONTEXT // local previews
)) {
eleventyConfig.ignores.add("src/static/sitemap.njk");
}


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>