Skip to content

Commit

Permalink
🔨 incorporate PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Oct 10, 2024
1 parent 50c4def commit e98a00d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
8 changes: 7 additions & 1 deletion functions/_common/grapherRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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],
},
]
})
Expand Down
4 changes: 3 additions & 1 deletion functions/_common/readmeTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getCitationLong,
prepareSourcesForDisplay,
uniqBy,
formatDate,
} from "@ourworldindata/utils"
import { CoreColumn } from "@ourworldindata/core-table"
import { Grapher } from "@ourworldindata/grapher"
Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions functions/grapher/[slug].ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/@ourworldindata/utils/src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,8 @@ export const getIndexableKeys = Object.keys as <T extends object>(
obj: T
) => Array<keyof T>

/** Formats a date like this: "October 10, 2024"
*/
export const formatDate = (date: Date): string => {
return date.toLocaleDateString("en-US", {
year: "numeric",
Expand Down

0 comments on commit e98a00d

Please sign in to comment.