Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 correctly parse URLs in gdoc front matter #3526

Merged
merged 2 commits into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion db/model/Gdoc/archieToEnriched.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -305,6 +305,15 @@ 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") {
// this is safe to call on everything because it falls back to `value` if it's not an <a> tag
parsed[key] = extractUrl(value)
}
}

// Parse elements of the ArchieML into enrichedBlocks
parsed.body = compact(parsed.body.map(parseRawBlocksToEnrichedBlocks))

Expand Down