Skip to content

Commit 1207158

Browse files
authored
fix(ssr): remove unnecessary robots tags (#11139)
* fix(ssr): remove unnecessary robots tags 1. Robots tag for 404 page is unnecessary, as it is ignored anyways. 2. Robots tag with value "index, follow" is unnecessary, as it is the default. * test(spas): update expectations
1 parent f4c2388 commit 1207158

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

Diff for: ssr/render.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,12 @@ export default function render(
209209
}</script>`;
210210

211211
const robotsContent =
212-
!ALWAYS_ALLOW_ROBOTS ||
213-
(doc && doc.noIndexing) ||
214-
pageNotFound ||
215-
noIndexing
212+
!ALWAYS_ALLOW_ROBOTS || (doc && doc.noIndexing) || noIndexing
216213
? "noindex, nofollow"
217-
: "index, follow";
218-
const robotsMeta = `<meta name="robots" content="${robotsContent}">`;
214+
: "";
215+
const robotsMeta = robotsContent
216+
? `<meta name="robots" content="${robotsContent}">`
217+
: "";
219218
const rssLink = `<link rel="alternate" type="application/rss+xml" title="MDN Blog RSS Feed" href="${BASE_URL}/${DEFAULT_LOCALE}/blog/rss.xml" hreflang="en" />`;
220219
const ssr_data = [...translations, ...WEBFONT_TAGS, rssLink, robotsMeta];
221220
let html = buildHtml;

Diff for: testing/tests/index.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ test("content built foo page", () => {
119119
`https://developer.mozilla.org${doc.mdn_url}`
120120
);
121121

122-
expect($('meta[name="robots"]').attr("content")).toBe("index, follow");
122+
expect($('meta[name="robots"]')).toHaveLength(0);
123123

124124
// The HTML should contain the Google Analytics snippet.
125125
// The ID should match what's set in `.env.testing`.
@@ -1179,7 +1179,7 @@ test("404 page", () => {
11791179
const $ = cheerio.load(html);
11801180
expect($("title").text()).toContain("Page not found");
11811181
expect($("h1").text()).toContain("Page not found");
1182-
expect($('meta[name="robots"]').attr("content")).toBe("noindex, nofollow");
1182+
expect($('meta[name="robots"]')).toHaveLength(0);
11831183
expect($('meta[property="og:locale"]').attr("content")).toBe("en_US");
11841184
});
11851185

@@ -1190,7 +1190,7 @@ test("plus page", () => {
11901190
const html = fs.readFileSync(htmlFile, "utf-8");
11911191
const $ = cheerio.load(html);
11921192
expect($("title").text()).toContain("Plus");
1193-
expect($('meta[name="robots"]').attr("content")).toBe("index, follow");
1193+
expect($('meta[name="robots"]')).toHaveLength(0);
11941194
});
11951195

11961196
test("plus collections page", () => {

0 commit comments

Comments
 (0)