Skip to content

Commit 734c0b6

Browse files
authored
fix(search): use "noindex, follow" robots tag + remove robots.txt exclude (#11140)
* fix(spas): set "noindex, follow" for search Previously, it was "index, follow", but we do not want to index MDN full-text search results. * fix(robots): remove /search from robots.txt
1 parent bd4aad4 commit 734c0b6

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

Diff for: build/spas.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export async function buildSPAs(options: {
140140

141141
const SPAs = [
142142
{ prefix: "play", pageTitle: "Playground | MDN" },
143-
{ prefix: "search", pageTitle: "Search" },
143+
{ prefix: "search", pageTitle: "Search", onlyFollow: true },
144144
{ prefix: "plus", pageTitle: MDN_PLUS_TITLE },
145145
{
146146
prefix: "plus/ai-help",
@@ -177,12 +177,13 @@ export async function buildSPAs(options: {
177177
},
178178
];
179179
const locale = VALID_LOCALES.get(pathLocale) || pathLocale;
180-
for (const { prefix, pageTitle, noIndexing } of SPAs) {
180+
for (const { prefix, pageTitle, noIndexing, onlyFollow } of SPAs) {
181181
const url = `/${locale}/${prefix}`;
182182
const context = {
183183
pageTitle,
184184
locale,
185185
noIndexing,
186+
onlyFollow,
186187
};
187188

188189
const html = renderCanonicalHTML(url, context);

Diff for: libs/types/hydration.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ interface HydrationData<T = any, S = any> {
88
pageTitle?: any;
99
possibleLocales?: any;
1010
locale?: any;
11-
noIndexing?: any;
11+
noIndexing?: boolean;
12+
onlyFollow?: boolean;
1213
image?: string | null;
1314
}
1415

Diff for: ssr/render.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ export default function render(
106106
pageTitle = null,
107107
possibleLocales = null,
108108
locale = null,
109-
noIndexing = null,
109+
noIndexing = false,
110+
onlyFollow = false,
110111
image = null,
111112
blogMeta = null,
112113
}: HydrationData = {}
@@ -211,7 +212,9 @@ export default function render(
211212
const robotsContent =
212213
!ALWAYS_ALLOW_ROBOTS || (doc && doc.noIndexing) || noIndexing
213214
? "noindex, nofollow"
214-
: "";
215+
: onlyFollow
216+
? "noindex, follow"
217+
: "";
215218
const robotsMeta = robotsContent
216219
? `<meta name="robots" content="${robotsContent}">`
217220
: "";

Diff for: tool/build-robots-txt.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
import fs from "node:fs";
77

8-
import { VALID_LOCALES } from "../libs/constants/index.js";
98
import { ALWAYS_ALLOW_ROBOTS } from "../libs/env/index.js";
109

1110
const ALLOW_TEXT = `
@@ -25,12 +24,6 @@ Disallow: /
2524
`;
2625

2726
export async function runBuildRobotsTxt(outfile: string) {
28-
let content = ALWAYS_ALLOW_ROBOTS ? ALLOW_TEXT : DISALLOW_TEXT;
29-
if (ALWAYS_ALLOW_ROBOTS) {
30-
// Append extra lines specifically when we do allow robots.
31-
for (const locale of VALID_LOCALES.values()) {
32-
content += `Disallow: /${locale}/search\n`;
33-
}
34-
}
27+
const content = ALWAYS_ALLOW_ROBOTS ? ALLOW_TEXT : DISALLOW_TEXT;
3528
fs.writeFileSync(outfile, `${content.trim()}\n`, "utf-8");
3629
}

0 commit comments

Comments
 (0)