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

Better automatic links to topic pages #2802

Merged
merged 1 commit into from
Oct 24, 2023
Merged
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
17 changes: 16 additions & 1 deletion site/DataPageV2Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ const getDateRange = (dateRange: string): string | null => {
return null
}

const slugify_topic = (topic: string) => {
// This is a heuristic to map from free form tag texts to topic page URLs. We'll
// have to switch to explicitly stored URLs or explicit links between tags and topic pages
// soon but for the time being this makes sure that "CO2 & Greenhouse Gas Emissions" can be automatically
// linked to /co2-and-greenhouse-gas-emissions
// Note that the heuristic fails for a few cases like "HIV/AIDS" or "Mpox (Monkeypox)"
const replaced = topic
.replace("&", "-and-")
.replace("'", "")
.replace("+", "")
return slugify(replaced)
}

export const DataPageV2Content = ({
datapageData,
grapherConfig,
Expand Down Expand Up @@ -228,7 +241,9 @@ export const DataPageV2Content = ({
{datapageData.topicTagsLinks?.map(
(topic: any) => (
<a
href={`/${slugify(topic)}`}
href={`/${slugify_topic(
topic
)}`}
key={topic}
>
{topic}
Expand Down