From 90e1f187062e9f4e7716efc72274bd0dc77ebcb8 Mon Sep 17 00:00:00 2001 From: Daniel Bachler Date: Wed, 18 Oct 2023 11:17:20 +0200 Subject: [PATCH] data-page-better-slugify --- site/DataPageV2Content.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/site/DataPageV2Content.tsx b/site/DataPageV2Content.tsx index aa3cf23cd9a..c6dd0604b21 100644 --- a/site/DataPageV2Content.tsx +++ b/site/DataPageV2Content.tsx @@ -74,6 +74,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, @@ -230,7 +243,9 @@ export const DataPageV2Content = ({ {datapageData.topicTagsLinks?.map( (topic: any) => ( {topic}