From 4359fe2ebbc11d3cd945df77141ad855d1f228a8 Mon Sep 17 00:00:00 2001 From: Mikaal Naik Date: Tue, 14 Jul 2026 10:46:50 -0400 Subject: [PATCH] fix: links to world bank and stats can --- .../CombinedSectionChart.tsx | 3 +- .../prosperity-dashboard/IndicatorChart.tsx | 3 +- .../prosperity-dashboard/[section]/page.tsx | 6 ++-- src/lib/api/economy.ts | 33 +++++++++++++++++++ 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/app/prosperity-dashboard/CombinedSectionChart.tsx b/src/app/prosperity-dashboard/CombinedSectionChart.tsx index 7a1e22e..4967d8a 100644 --- a/src/app/prosperity-dashboard/CombinedSectionChart.tsx +++ b/src/app/prosperity-dashboard/CombinedSectionChart.tsx @@ -12,6 +12,7 @@ import { } from "@buildcanada/charts"; import { humanizeSourceName, + humanizeSourceUrl, type EconomySeriesResponse, } from "@/lib/api/economy"; import { @@ -95,7 +96,7 @@ function buildGrapherState( { id: 1, title: humanizeSourceName(source.name), - urlMain: source.url ?? undefined, + urlMain: humanizeSourceUrl(source.name, source.url) ?? undefined, datePublished: source.last_fetched_at ?? undefined, }, ] diff --git a/src/app/prosperity-dashboard/IndicatorChart.tsx b/src/app/prosperity-dashboard/IndicatorChart.tsx index ba15871..c491fb7 100644 --- a/src/app/prosperity-dashboard/IndicatorChart.tsx +++ b/src/app/prosperity-dashboard/IndicatorChart.tsx @@ -12,6 +12,7 @@ import { } from "@buildcanada/charts"; import { humanizeSourceName, + humanizeSourceUrl, type EconomySeriesResponse, } from "@/lib/api/economy"; import { @@ -99,7 +100,7 @@ function buildGrapherState( { id: 1, title: humanizeSourceName(source.name), - urlMain: source.url ?? undefined, + urlMain: humanizeSourceUrl(source.name, source.url) ?? undefined, datePublished: source.last_fetched_at ?? undefined, }, ] diff --git a/src/app/prosperity-dashboard/[section]/page.tsx b/src/app/prosperity-dashboard/[section]/page.tsx index 53c64be..11295e2 100644 --- a/src/app/prosperity-dashboard/[section]/page.tsx +++ b/src/app/prosperity-dashboard/[section]/page.tsx @@ -7,6 +7,7 @@ import { getSiteConfig } from "@/lib/api"; import { getEconomicSeries, humanizeSourceName, + humanizeSourceUrl, type EconomySeriesResponse, } from "@/lib/api/economy"; import { PageHeader } from "@/components/ui/page-header"; @@ -63,12 +64,13 @@ function SourceLine({ response }: { response: EconomySeriesResponse }) { ? formatFetchedDate(source.last_fetched_at) : ""; const sourceName = humanizeSourceName(source.name); + const sourceUrl = humanizeSourceUrl(source.name, source.url); return (

Source:{" "} - {source.url ? ( + {sourceUrl ? ( = { + econ_statcan_gini_after_tax: "11-10-0134", + econ_statcan_low_income_dynamics: "11-10-0024", + econ_statcan_housing_starts: "34-10-0126", + econ_statcan_rental_vacancy: "34-10-0127", + econ_statcan_crime_severity: "35-10-0026", + econ_statcan_crime_rate: "35-10-0177", + econ_statcan_cpi_essentials: "18-10-0004", + econ_statcan_gdp_monthly: "36-10-0434", +}; + +export function humanizeSourceUrl( + name: string, + url: string | null, +): string | null { + const table = STATCAN_TABLES[name]; + if (table) + return `https://www150.statcan.gc.ca/t1/tbl1/en/tv.action?pid=${table.replaceAll("-", "")}01`; + // World Bank source URLs are raw API queries (JSON dumps); link to the + // public indicator page instead. Worldwide Governance Indicators carry a + // GOV_WGI_ prefix in the API's source=3 dataset that the public catalog + // doesn't use (GOV_WGI_GE.EST -> GE.EST). + const worldBank = url?.match( + /^https:\/\/api\.worldbank\.org\/v2\/country\/[^/]+\/indicator\/([A-Za-z0-9._]+)/, + ); + if (worldBank) + return `https://data.worldbank.org/indicator/${worldBank[1].replace(/^GOV_WGI_/, "")}`; + return url; +} + // Annual data refreshed at most weekly; matches the API's Cache-Control max-age. const REVALIDATE = 3600;