From e98a00d11aeb891c22f0c5ee53065926b9d625b3 Mon Sep 17 00:00:00 2001 From: Daniel Bachler Date: Thu, 10 Oct 2024 14:07:44 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20incorporate=20PR=20feedback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/_common/grapherRenderer.ts | 8 +++++++- functions/_common/readmeTools.ts | 4 +++- functions/grapher/[slug].ts | 11 ----------- packages/@ourworldindata/utils/src/Util.ts | 2 ++ 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/functions/_common/grapherRenderer.ts b/functions/_common/grapherRenderer.ts index 1f5b52d27a9..5937f2a7069 100644 --- a/functions/_common/grapherRenderer.ts +++ b/functions/_common/grapherRenderer.ts @@ -54,8 +54,11 @@ export const extensions = { configJson: ".config.json", png: ".png", svg: ".svg", + csv: ".csv", + metadata: ".metadata.json", + readme: ".readme.md", + zip: ".zip", } - interface ImageOptions { pngWidth: number pngHeight: number @@ -454,6 +457,7 @@ function assembleMetadata(grapher: Grapher, searchParams: URLSearchParams) { : attributionShort || titleVariant const titleModifier = attributionString ? ` - ${attributionString}` : "" const titleLong = `${col.titlePublicOrDisplayName.title}${titleModifier}` + const dateDownloaded = new Date() return [ useShortNames ? shortName : col.name, @@ -477,6 +481,8 @@ function assembleMetadata(grapher: Grapher, searchParams: URLSearchParams) { citationShort, citationLong, fullMetadata: `https://api.ourworldindata.org/v1/indicators/${owidVariableId}.metadata.json`, + // date downloaded should be YYYY-MM-DD + dateDownloaded: dateDownloaded.toISOString().split("T")[0], }, ] }) diff --git a/functions/_common/readmeTools.ts b/functions/_common/readmeTools.ts index c15ff56d3d4..d323f27e062 100644 --- a/functions/_common/readmeTools.ts +++ b/functions/_common/readmeTools.ts @@ -12,6 +12,7 @@ import { getCitationLong, prepareSourcesForDisplay, uniqBy, + formatDate, } from "@ourworldindata/utils" import { CoreColumn } from "@ourworldindata/core-table" import { Grapher } from "@ourworldindata/grapher" @@ -241,10 +242,11 @@ export function constructReadme( const isSingleColumn = columns.length === 1 const sources = columns.flatMap((col) => [...columnReadmeText(col)]) let readme: string + const downloadDate = formatDate(new Date()) // formats the date as "October 10, 2024" if (isSingleColumn) readme = `# ${grapher.title} - Data package -This data package contains the data that powers the chart ["${grapher.title}"](${grapher.originUrl}) on the Our World in Data website. +This data package contains the data that powers the chart ["${grapher.title}"](${grapher.originUrl}) on the Our World in Data website. It was donwloaded on ${downloadDate}. ## CSV Structure diff --git a/functions/grapher/[slug].ts b/functions/grapher/[slug].ts index 88ae85a52d4..25bfb057566 100644 --- a/functions/grapher/[slug].ts +++ b/functions/grapher/[slug].ts @@ -16,17 +16,6 @@ import { handleThumbnailRequest } from "../_common/reusableHandlers.js" const { preflight, corsify } = cors({ allowMethods: ["GET", "OPTIONS", "HEAD"], }) -// We collect the possible extensions here so we can easily take them into account -// when handling redirects -export const extensions = { - configJson: ".config.json", - png: ".png", - svg: ".svg", - csv: ".csv", - metadata: ".metadata.json", - readme: ".readme.md", - zip: ".zip", -} const router = Router< IRequestStrict, diff --git a/packages/@ourworldindata/utils/src/Util.ts b/packages/@ourworldindata/utils/src/Util.ts index 96af7378925..05002360011 100644 --- a/packages/@ourworldindata/utils/src/Util.ts +++ b/packages/@ourworldindata/utils/src/Util.ts @@ -1315,6 +1315,8 @@ export const getIndexableKeys = Object.keys as ( obj: T ) => Array +/** Formats a date like this: "October 10, 2024" + */ export const formatDate = (date: Date): string => { return date.toLocaleDateString("en-US", { year: "numeric",