From 7dabf298606f120531652d0f39fca3618e1df4ee Mon Sep 17 00:00:00 2001 From: Ryan Hirsch Date: Tue, 16 Nov 2021 21:46:01 -0600 Subject: [PATCH] support multiple authors --- package.json | 1 + src/parser/__test__/feed.test.ts | 27 ++++++++++++++++++++++++++- src/parser/feed.ts | 8 ++++---- src/parser/types.ts | 2 +- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 2d78561..d942328 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "test:watch": "jest --watch", "start:dev": "esr src/dev.ts", "dev": "esr src/dev.ts", + "debug": "node --inspect-brk -r esbuild-runner/register ", "dev:watch": "ts-node-dev --respawn --no-notify src/dev.ts", "deps": "npm-run-all -p deps:*", "deps:person": "./scripts/update-person-enum.sh", diff --git a/src/parser/__test__/feed.test.ts b/src/parser/__test__/feed.test.ts index 1aa8400..705be16 100644 --- a/src/parser/__test__/feed.test.ts +++ b/src/parser/__test__/feed.test.ts @@ -763,12 +763,37 @@ describe("feed handling", () => { feed, ` Founders Fund + ` + ); + + const result = parseFeed(xml); + expect(result).toHaveProperty("author", ["Founders Fund"]); + }); + + it("extracts multiple authors", () => { + const xml = helpers.spliceFeed( + feed, + ` + Founders Fund + Person Fund + ` + ); + const result = parseFeed(xml); + expect(result).toHaveProperty("author", ["Founders Fund", "Person Fund"]); + }); + + it("ignores empty nodes", () => { + const xml = helpers.spliceFeed( + feed, + ` + + ` ); const result = parseFeed(xml); - expect(result).toHaveProperty("author", "Founders Fund"); + expect(result).not.toHaveProperty("author"); }); }); diff --git a/src/parser/feed.ts b/src/parser/feed.ts index bed3055..57d563a 100644 --- a/src/parser/feed.ts +++ b/src/parser/feed.ts @@ -525,11 +525,11 @@ function getPubSub( return { pubsub }; } -function getAuthor(feed: XmlNode): undefined | { author: string } { - const node = firstWithValue(feed["itunes:author"]); +function getAuthor(feed: XmlNode): undefined | { author: string[] } { + const nodes = ensureArray(feed["itunes:author"]).filter((n) => getText(n)); - if (node) { - return { author: getText(node) }; + if (nodes.length > 0) { + return { author: nodes }; } return undefined; } diff --git a/src/parser/types.ts b/src/parser/types.ts index 3b207e4..92493f7 100644 --- a/src/parser/types.ts +++ b/src/parser/types.ts @@ -113,7 +113,7 @@ export interface FeedObject { categories?: string[]; pubsub?: { hub?: string; self?: string; next?: string }; - author?: string; + author?: string[]; owner?: { email: string; name: string;