From 628c0124b63a4a29aa67d73ddd8ce07bb7252f46 Mon Sep 17 00:00:00 2001 From: Marcel Gerber Date: Tue, 4 Mar 2025 08:36:14 +0100 Subject: [PATCH] cleanup(explorer): remove `indexViewsSeparately` --- baker/sitemap.ts | 31 ++++------------ .../@ourworldindata/explorer/src/Explorer.tsx | 37 ------------------- .../explorer/src/ExplorerGrammar.ts | 6 --- .../explorer/src/ExplorerProgram.ts | 7 ---- site/ExplorerPage.tsx | 1 - site/Head.tsx | 5 +-- 6 files changed, 9 insertions(+), 78 deletions(-) diff --git a/baker/sitemap.ts b/baker/sitemap.ts index edc45c1cdc..73c551a99e 100644 --- a/baker/sitemap.ts +++ b/baker/sitemap.ts @@ -3,12 +3,7 @@ import { BAKED_BASE_URL, BAKED_GRAPHER_URL, } from "../settings/serverSettings.js" -import { - dayjs, - countries, - queryParamsToStr, - DbPlainChart, -} from "@ourworldindata/utils" +import { dayjs, countries, DbPlainChart } from "@ourworldindata/utils" import { EXPLORERS_ROUTE_FOLDER, ExplorerProgram, @@ -41,27 +36,15 @@ const xmlify = (url: SitemapUrl) => { ` } -const explorerToSitemapUrl = (program: ExplorerProgram): SitemapUrl[] => { - const baseUrl = `${BAKED_BASE_URL}/${EXPLORERS_ROUTE_FOLDER}/${program.slug}` +const explorerToSitemapUrl = (program: ExplorerProgram): SitemapUrl => { + const url = `${BAKED_BASE_URL}/${EXPLORERS_ROUTE_FOLDER}/${program.slug}` const lastmod = program.lastCommit?.date ? dayjs(program.lastCommit.date).format("YYYY-MM-DD") : undefined - if (program.indexViewsSeparately) { - // return an array containing the URLs to each view of the explorer - return program.decisionMatrix - .allDecisionsAsQueryParams() - .map((params) => ({ - loc: baseUrl + queryParamsToStr(params), - lastmod, - })) - } else { - return [ - { - loc: baseUrl, - lastmod, - }, - ] + return { + loc: url, + lastmod, } } @@ -155,7 +138,7 @@ export const makeSitemap = async ( lastmod: dayjs(c.updatedAt).format("YYYY-MM-DD"), })) ) - .concat(explorers.flatMap(explorerToSitemapUrl)) + .concat(explorers.map(explorerToSitemapUrl)) .concat( authorPages.map((a) => ({ loc: urljoin(BAKED_BASE_URL, "team", a.slug), diff --git a/packages/@ourworldindata/explorer/src/Explorer.tsx b/packages/@ourworldindata/explorer/src/Explorer.tsx index 66750bbcdf..6b941ae0d6 100644 --- a/packages/@ourworldindata/explorer/src/Explorer.tsx +++ b/packages/@ourworldindata/explorer/src/Explorer.tsx @@ -333,8 +333,6 @@ export class Explorer ) } - if (this.props.isInStandalonePage) this.setCanonicalUrl() - this.grapher?.populateFromQueryParams(url.queryParams) exposeInstanceOnWindow(this, "explorer") @@ -343,32 +341,6 @@ export class Explorer this.updateEntityPickerTable() // call for the first time to initialize EntityPicker } - componentDidUpdate() { - this.maybeUpdatePageTitle() - } - - private maybeUpdatePageTitle() { - // expose the title of the current view to the Google crawler on non-default views - // of opted-in standalone explorer pages - if ( - this.props.isInStandalonePage && - this.grapher && - this.explorerProgram.indexViewsSeparately && - document.location.search - ) { - document.title = `${this.grapher.displayTitle} - Our World in Data` - } - } - - private setCanonicalUrl() { - // see https://developers.google.com/search/docs/advanced/javascript/javascript-seo-basics#properly-inject-canonical-links - // Note that the URL is not updated when the user interacts with the explorer - this should be enough for Googlebot I hope. - const canonicalElement = document.createElement("link") - canonicalElement.setAttribute("rel", "canonical") - canonicalElement.href = this.canonicalUrlForGoogle - document.head.appendChild(canonicalElement) - } - private attachEventListeners() { if (typeof window !== "undefined" && "ResizeObserver" in window) { const onResizeThrottled = debounce(this.onResize, 200, { @@ -834,15 +806,6 @@ export class Explorer return Url.fromURL(this.baseUrl).setQueryParams(this.queryParams) } - @computed get canonicalUrlForGoogle(): string { - // we want the canonical URL to match what's in the sitemap, so it's different depending on indexViewsSeparately - if (this.explorerProgram.indexViewsSeparately) - return Url.fromURL(this.baseUrl).setQueryParams( - this.currentChoiceParams - ).fullUrl - else return this.baseUrl - } - private bindToWindow() { // There is a surprisingly considerable performance overhead to updating the url // while animating, so we debounce to allow e.g. smoother timelines diff --git a/packages/@ourworldindata/explorer/src/ExplorerGrammar.ts b/packages/@ourworldindata/explorer/src/ExplorerGrammar.ts index df6c3b0be8..3c88e3bc3c 100644 --- a/packages/@ourworldindata/explorer/src/ExplorerGrammar.ts +++ b/packages/@ourworldindata/explorer/src/ExplorerGrammar.ts @@ -99,12 +99,6 @@ export const ExplorerGrammar: Grammar = { keyword: "isPublished", description: "Set to true to make this Explorer public.", }, - indexViewsSeparately: { - ...BooleanCellDef, - keyword: "indexViewsSeparately", - description: - "Set to true to make Google index every view of this explorer, rather than only indexing the default view.", - }, wpBlockId: { ...IntegerCellDef, keyword: "wpBlockId", diff --git a/packages/@ourworldindata/explorer/src/ExplorerProgram.ts b/packages/@ourworldindata/explorer/src/ExplorerProgram.ts index 6fb381e44c..9a2130d001 100644 --- a/packages/@ourworldindata/explorer/src/ExplorerProgram.ts +++ b/packages/@ourworldindata/explorer/src/ExplorerProgram.ts @@ -205,13 +205,6 @@ export class ExplorerProgram extends GridProgram { ) } - get indexViewsSeparately() { - return ( - this.getLineValue(ExplorerGrammar.indexViewsSeparately.keyword) === - GridBoolean.true - ) - } - get wpBlockId() { const blockIdString = this.getLineValue( ExplorerGrammar.wpBlockId.keyword diff --git a/site/ExplorerPage.tsx b/site/ExplorerPage.tsx index ab40ce315b..7c9c71ad35 100644 --- a/site/ExplorerPage.tsx +++ b/site/ExplorerPage.tsx @@ -116,7 +116,6 @@ window.Explorer.renderSingleExplorerOnExplorerPage(explorerProgram, grapherConfi { - const { canonicalUrl, hideCanonicalUrl, baseUrl } = props + const { canonicalUrl, baseUrl } = props const pageTitle = props.pageTitle || `Our World in Data` const fullPageTitle = props.pageTitle ? `${props.pageTitle} - Our World in Data` @@ -71,7 +70,7 @@ export const Head = (props: { /> {fullPageTitle} - {!hideCanonicalUrl && } +