Skip to content

Commit

Permalink
🔨 validate the first block in a di to be an image
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Feb 7, 2025
1 parent 613e40b commit 91bdd81
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions adminSiteClient/gdocsValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,32 +213,34 @@ function validateDataInsightImage(
gdoc: OwidGdocDataInsightInterface,
errors: OwidGdocErrorMessage[]
) {
const image = gdoc.content.body.find((block) => block.type === "image")
if (!image) {
const firstBlock = gdoc.content.body[0]
if (!firstBlock || firstBlock.type !== "image") {
errors.push({
property: "body",
type: OwidGdocErrorMessageType.Warning,
message: `Data insight is missing an image.`,
message: `The first block in a data insight should be an image.`,
})
} else {
for (const property of ["filename"] as const) {
if (!image[property]) {
errors.push({
property: "body",
type: OwidGdocErrorMessageType.Error,
message: `Data insight image is missing ${property}`,
})
}
if (
image[property] &&
getFilenameExtension(image[property]) !== "png"
) {
errors.push({
property: "body",
type: OwidGdocErrorMessageType.Warning,
message: `Data insight ${property} should be a PNG`,
})
}
return
}

const image = firstBlock
for (const property of ["filename"] as const) {
if (!image[property]) {
errors.push({
property: "body",
type: OwidGdocErrorMessageType.Error,
message: `Data insight image is missing ${property}`,
})
}
if (
image[property] &&
getFilenameExtension(image[property]) !== "png"
) {
errors.push({
property: "body",
type: OwidGdocErrorMessageType.Warning,
message: `Data insight ${property} should be a PNG`,
})
}
}
}
Expand Down

0 comments on commit 91bdd81

Please sign in to comment.