Skip to content

Commit

Permalink
Add prismic linting step for audio/video duration format (xx:xx)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpmccormick committed Sep 18, 2024
1 parent 7416ffd commit 24c5a98
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions prismic-model/lintPrismicData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -224,6 +253,7 @@ async function run() {
...detectNonPromoImageStories(doc),
...detectIncompleteContributorSameAs(doc),
...detectMissingUidDocuments(doc),
...detectIncorrectAudioVideoDuration(doc),
];

totalErrors += errors.length;
Expand Down

0 comments on commit 24c5a98

Please sign in to comment.