From 24c5a9868704b660e92ae15451688661b599af5f Mon Sep 17 00:00:00 2001 From: davidpmccormick Date: Wed, 18 Sep 2024 11:06:52 +0100 Subject: [PATCH 1/2] Add prismic linting step for audio/video duration format (xx:xx) --- prismic-model/lintPrismicData.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/prismic-model/lintPrismicData.ts b/prismic-model/lintPrismicData.ts index d4e5b44765..1279dd4561 100644 --- a/prismic-model/lintPrismicData.ts +++ b/prismic-model/lintPrismicData.ts @@ -144,6 +144,35 @@ function detectNonPromoImageStories(doc: any): string[] { return []; } +function detectIncorrectAudioVideoDuration(doc: any): string[] { + const guideStopSlices = + doc?.data?.slices?.filter(s => s.slice_type === 'guide_stop') || []; + const regex = /^\d{2}:\d{2}$/; // e.g. 03:30 + + const audioErrors = guideStopSlices + .filter( + s => + Boolean(s.primary.audio_duration) && + !s.primary.audio_duration.match(regex) + ) + .map( + e => + `The audio_duration for should be in the format xx:xx but it is ${e.primary.audio_duration}` + ); + const videoErrors = guideStopSlices + .filter( + s => + Boolean(s.primary.video_duration) && + !s.primary.video_duration.match(regex) + ) + .map( + e => + `The video_duration for should be in the format xx:xx but it is ${e.primary.video_duration}` + ); + + return [...audioErrors, ...videoErrors]; +} + // Contributors have a `sameAs` field which is used to generate links to // their pages elsewhere, e.g. social media or organisation websites. // @@ -224,6 +253,7 @@ async function run() { ...detectNonPromoImageStories(doc), ...detectIncompleteContributorSameAs(doc), ...detectMissingUidDocuments(doc), + ...detectIncorrectAudioVideoDuration(doc), ]; totalErrors += errors.length; From b87de1bc5ac10b34f1e8b7eec590c13cda548826 Mon Sep 17 00:00:00 2001 From: davidpmccormick Date: Wed, 18 Sep 2024 11:35:52 +0100 Subject: [PATCH 2/2] Make regex a bit more resilient --- prismic-model/lintPrismicData.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prismic-model/lintPrismicData.ts b/prismic-model/lintPrismicData.ts index 1279dd4561..3afaab075a 100644 --- a/prismic-model/lintPrismicData.ts +++ b/prismic-model/lintPrismicData.ts @@ -147,7 +147,7 @@ function detectNonPromoImageStories(doc: any): string[] { function detectIncorrectAudioVideoDuration(doc: any): string[] { const guideStopSlices = doc?.data?.slices?.filter(s => s.slice_type === 'guide_stop') || []; - const regex = /^\d{2}:\d{2}$/; // e.g. 03:30 + const regex = /^(\d{2,}:)?[0-5][0-9]:[0-5][0-9]$/; // e.g. 03:30 (optionally 01:03:30) const audioErrors = guideStopSlices .filter(