Skip to content

Commit

Permalink
Merge pull request #2923 from owid/owid-cloud-links
Browse files Browse the repository at this point in the history
🎉 add warning if linking to owid.cloud in gdocs
  • Loading branch information
ikesau authored Nov 29, 2023
2 parents 047690b + 8509d3e commit fdf2eaa
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion db/model/Gdoc/rawToEnriched.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -961,17 +963,35 @@ 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",
})

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,
}
}

Expand Down

0 comments on commit fdf2eaa

Please sign in to comment.