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

fix(search): use "noindex, follow" robots tag + remove robots.txt exclude #11140

Merged
merged 3 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -24,12 +23,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");
}
Loading