Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions common/strip-serial-block-suffix.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
32 changes: 32 additions & 0 deletions common/tests/strip-serial-block-suffix.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading