diff --git a/common/strip-serial-block-suffix.js b/common/strip-serial-block-suffix.js index 71e565de..0782ae65 100644 --- a/common/strip-serial-block-suffix.js +++ b/common/strip-serial-block-suffix.js @@ -19,10 +19,18 @@ const episodeBlock = /\s*\((?:episodes?|eps?)\s*\d[^)]*\)/gi; // list - describes a sitting rather than names a film. const partBlock = /\s*\(parts?\s*\d+\s*(?:[-–—]|to|,|&|and)\s*\d[^)]*\)/gi; +// A competition screened over several sittings is billed one part at a time, +// with whatever the sitting adds after it: "Short Film Competition Part 1 + +// Q&A". Unlike a film, a competition never has a part in its own name, so the +// part and everything after it can go - the rest belongs to that one sitting. +const competitionPart = + /(\bcompetition)\s*[-–—:,]?\s*\(?part\s*(?:\d+|[ivx]+)\b.*$/i; + function stripSerialBlockSuffix(title = "") { return title .replace(episodeBlock, "") .replace(partBlock, "") + .replace(competitionPart, "$1") .replace(/\s+/g, " ") .replace(/\s*[-–—:+]\s*$/, "") .trim(); diff --git a/common/tests/strip-serial-block-suffix.test.js b/common/tests/strip-serial-block-suffix.test.js index 8134c7a4..45b22081 100644 --- a/common/tests/strip-serial-block-suffix.test.js +++ b/common/tests/strip-serial-block-suffix.test.js @@ -61,6 +61,38 @@ describe("stripSerialBlockSuffix", () => { ); }); + test("drops a competition part and what the sitting adds after it", () => { + expect( + stripSerialBlockSuffix( + "Turn Up Film Festival - Short Film Competition Part 1 + Q&A", + ), + ).toEqual("Turn Up Film Festival - Short Film Competition"); + }); + + test("drops a competition part however it's set off", () => { + expect(stripSerialBlockSuffix("Animation Competition - Part 2")).toEqual( + "Animation Competition", + ); + expect(stripSerialBlockSuffix("Shorts Competition (Part 3)")).toEqual( + "Shorts Competition", + ); + expect(stripSerialBlockSuffix("Shorts Competition: Part IV")).toEqual( + "Shorts Competition", + ); + }); + + test("keeps a part that isn't a competition's", () => { + expect(stripSerialBlockSuffix("Dune: Part Two + Q&A")).toEqual( + "Dune: Part Two + Q&A", + ); + }); + + test("keeps a competition with no part", () => { + expect(stripSerialBlockSuffix("Short Film Competition + Q&A")).toEqual( + "Short Film Competition + Q&A", + ); + }); + test("leaves a title with no block untouched", () => { expect(stripSerialBlockSuffix("Picnic at Hanging Rock")).toEqual( "Picnic at Hanging Rock",