From 91bdd816b6303fc281efafcc9345754197fc5bda Mon Sep 17 00:00:00 2001 From: Sophia Mersmann Date: Fri, 7 Feb 2025 10:45:14 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20validate=20the=20first=20block?= =?UTF-8?q?=20in=20a=20di=20to=20be=20an=20image?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adminSiteClient/gdocsValidation.ts | 46 ++++++++++++++++-------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/adminSiteClient/gdocsValidation.ts b/adminSiteClient/gdocsValidation.ts index cb8bd02a11..ef21a3068a 100644 --- a/adminSiteClient/gdocsValidation.ts +++ b/adminSiteClient/gdocsValidation.ts @@ -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`, + }) } } }