From 8509d3e591f04b2b6ef62c8a3ebc751265446557 Mon Sep 17 00:00:00 2001 From: Ike Saunders Date: Sun, 12 Nov 2023 19:34:13 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=89=20add=20warning=20if=20linking=20t?= =?UTF-8?q?o=20owid.cloud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/model/Gdoc/rawToEnriched.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/db/model/Gdoc/rawToEnriched.ts b/db/model/Gdoc/rawToEnriched.ts index 608bd0a3edc..efdd29084aa 100644 --- a/db/model/Gdoc/rawToEnriched.ts +++ b/db/model/Gdoc/rawToEnriched.ts @@ -109,12 +109,14 @@ import { tableTemplates, RawBlockBlockquote, EnrichedBlockBlockquote, + traverseEnrichedSpan, } from "@ourworldindata/utils" import { checkIsInternalLink } from "@ourworldindata/components" import { extractUrl, getTitleSupertitleFromHeadingText, parseAuthors, + spansToSimpleString, } from "./gdocUtils.js" import { htmlToEnrichedTextBlock, @@ -961,6 +963,8 @@ export const parseText = (raw: RawBlockText): EnrichedBlockText => { parseErrors: [error], }) + const parseErrors: ParseError[] = [] + if (typeof raw.value !== "string") return createError({ message: "Value is a not a string", @@ -968,10 +972,26 @@ export const parseText = (raw: RawBlockText): EnrichedBlockText => { const value = htmlToSpans(raw.value) + value.forEach((node) => + traverseEnrichedSpan(node, (span) => { + if ( + span.spanType === "span-link" && + span.url.includes("owid.cloud") + ) { + parseErrors.push({ + message: `Link with text "${spansToSimpleString( + span.children + )}" is linking to owid.cloud instead of ourworldindata.org`, + isWarning: true, + }) + } + }) + ) + return { type: "text", value, - parseErrors: [], + parseErrors, } }