Skip to content

Commit

Permalink
cleanup(explorer): remove indexViewsSeparately
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Mar 4, 2025
1 parent cb01ebb commit 628c012
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 78 deletions.
31 changes: 7 additions & 24 deletions baker/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -41,27 +36,15 @@ const xmlify = (url: SitemapUrl) => {
</url>`
}

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,
}
}

Expand Down Expand Up @@ -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),
Expand Down
37 changes: 0 additions & 37 deletions packages/@ourworldindata/explorer/src/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,6 @@ export class Explorer
)
}

if (this.props.isInStandalonePage) this.setCanonicalUrl()

this.grapher?.populateFromQueryParams(url.queryParams)

exposeInstanceOnWindow(this, "explorer")
Expand All @@ -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, {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions packages/@ourworldindata/explorer/src/ExplorerGrammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 0 additions & 7 deletions packages/@ourworldindata/explorer/src/ExplorerProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion site/ExplorerPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ window.Explorer.renderSingleExplorerOnExplorerPage(explorerProgram, grapherConfi
<Html>
<Head
canonicalUrl={`${baseUrl}/${EXPLORERS_ROUTE_FOLDER}/${slug}`}
hideCanonicalUrl // explorers set their canonical url dynamically
pageTitle={`${explorerTitle} Data Explorer`}
pageDesc={explorerSubtitle}
imageUrl={thumbnail}
Expand Down
5 changes: 2 additions & 3 deletions site/Head.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=

export const Head = (props: {
canonicalUrl: string
hideCanonicalUrl?: boolean
pageTitle?: string
pageDesc?: string
imageUrl?: string
Expand All @@ -44,7 +43,7 @@ export const Head = (props: {
}
staticAssetMap?: AssetMap
}) => {
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`
Expand All @@ -71,7 +70,7 @@ export const Head = (props: {
/>
<title>{fullPageTitle}</title>
<meta name="description" content={pageDesc} />
{!hideCanonicalUrl && <link rel="canonical" href={canonicalUrl} />}
<link rel="canonical" href={canonicalUrl} />
<link
rel="alternate"
type="application/atom+xml"
Expand Down

0 comments on commit 628c012

Please sign in to comment.