From 74f9b24fef69595fa27b013ed1dcfabee76cc8d5 Mon Sep 17 00:00:00 2001 From: Ike Saunders Date: Mon, 22 Apr 2024 09:47:44 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20correctly=20parse=20URLs=20i?= =?UTF-8?q?n=20gdoc=20front=20matter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/model/Gdoc/archieToEnriched.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/db/model/Gdoc/archieToEnriched.ts b/db/model/Gdoc/archieToEnriched.ts index 55dc94e93fb..86c3940c219 100644 --- a/db/model/Gdoc/archieToEnriched.ts +++ b/db/model/Gdoc/archieToEnriched.ts @@ -26,7 +26,7 @@ import { import { convertHeadingTextToId } from "@ourworldindata/components" import { parseRawBlocksToEnrichedBlocks, parseRefs } from "./rawToEnriched.js" import urlSlug from "url-slug" -import { parseAuthors, spansToSimpleString } from "./gdocUtils.js" +import { extractUrl, parseAuthors, spansToSimpleString } from "./gdocUtils.js" import { htmlToSimpleTextBlock } from "./htmlToEnriched.js" import { RESEARCH_AND_WRITING_DEFAULT_HEADING } from "@ourworldindata/types" @@ -305,6 +305,14 @@ export const archieToEnriched = ( if (parsed[key] === "false") parsed[key] = false } + // Convert URL front-matter properties to URLs + for (const key of Object.keys(parsed)) { + const value = parsed[key] + if (typeof value === "string") { + parsed[key] = extractUrl(value) + } + } + // Parse elements of the ArchieML into enrichedBlocks parsed.body = compact(parsed.body.map(parseRawBlocksToEnrichedBlocks)) From 489c85491a9a79972dc4c2aa2747114433e7caa8 Mon Sep 17 00:00:00 2001 From: Ike Saunders Date: Mon, 22 Apr 2024 18:37:19 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=20add=20comment=20to=20URL=20extr?= =?UTF-8?q?action=20step=20in=20archieToEnriched?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/model/Gdoc/archieToEnriched.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/db/model/Gdoc/archieToEnriched.ts b/db/model/Gdoc/archieToEnriched.ts index 86c3940c219..554e1958978 100644 --- a/db/model/Gdoc/archieToEnriched.ts +++ b/db/model/Gdoc/archieToEnriched.ts @@ -309,6 +309,7 @@ export const archieToEnriched = ( for (const key of Object.keys(parsed)) { const value = parsed[key] if (typeof value === "string") { + // this is safe to call on everything because it falls back to `value` if it's not an tag parsed[key] = extractUrl(value) } }