Skip to content

Commit

Permalink
fix(search): use "noindex, follow" robots tag + remove robots.txt exc…
Browse files Browse the repository at this point in the history
…lude (#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
  • Loading branch information
caugner authored May 27, 2024
1 parent bd4aad4 commit 734c0b6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
5 changes: 3 additions & 2 deletions build/spas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export async function buildSPAs(options: {

const SPAs = [
{ prefix: "play", pageTitle: "Playground | MDN" },
{ prefix: "search", pageTitle: "Search" },
{ prefix: "search", pageTitle: "Search", onlyFollow: true },
{ prefix: "plus", pageTitle: MDN_PLUS_TITLE },
{
prefix: "plus/ai-help",
Expand Down Expand Up @@ -177,12 +177,13 @@ export async function buildSPAs(options: {
},
];
const locale = VALID_LOCALES.get(pathLocale) || pathLocale;
for (const { prefix, pageTitle, noIndexing } of SPAs) {
for (const { prefix, pageTitle, noIndexing, onlyFollow } of SPAs) {
const url = `/${locale}/${prefix}`;
const context = {
pageTitle,
locale,
noIndexing,
onlyFollow,
};

const html = renderCanonicalHTML(url, context);
Expand Down
3 changes: 2 additions & 1 deletion libs/types/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ interface HydrationData<T = any, S = any> {
pageTitle?: any;
possibleLocales?: any;
locale?: any;
noIndexing?: any;
noIndexing?: boolean;
onlyFollow?: boolean;
image?: string | null;
}

Expand Down
7 changes: 5 additions & 2 deletions ssr/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ export default function render(
pageTitle = null,
possibleLocales = null,
locale = null,
noIndexing = null,
noIndexing = false,
onlyFollow = false,
image = null,
blogMeta = null,
}: HydrationData = {}
Expand Down Expand Up @@ -211,7 +212,9 @@ export default function render(
const robotsContent =
!ALWAYS_ALLOW_ROBOTS || (doc && doc.noIndexing) || noIndexing
? "noindex, nofollow"
: "";
: onlyFollow
? "noindex, follow"
: "";
const robotsMeta = robotsContent
? `<meta name="robots" content="${robotsContent}">`
: "";
Expand Down
9 changes: 1 addition & 8 deletions tool/build-robots-txt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
import fs from "node:fs";

import { VALID_LOCALES } from "../libs/constants/index.js";
import { ALWAYS_ALLOW_ROBOTS } from "../libs/env/index.js";

const ALLOW_TEXT = `
Expand All @@ -25,12 +24,6 @@ Disallow: /
`;

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

0 comments on commit 734c0b6

Please sign in to comment.