Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support multiple authors #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 26 additions & 1 deletion src/parser/__test__/feed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,12 +763,37 @@ describe("feed handling", () => {
feed,
`
<itunes:author>Founders Fund</itunes:author>
`
);

const result = parseFeed(xml);
expect(result).toHaveProperty("author", ["Founders Fund"]);
});

it("extracts multiple authors", () => {
const xml = helpers.spliceFeed(
feed,
`
<itunes:author>Founders Fund</itunes:author>
<itunes:author>Person Fund</itunes:author>
`
);

const result = parseFeed(xml);
expect(result).toHaveProperty("author", ["Founders Fund", "Person Fund"]);
});

it("ignores empty nodes", () => {
const xml = helpers.spliceFeed(
feed,
`
<itunes:author></itunes:author>
<itunes:author> </itunes:author>
`
);

const result = parseFeed(xml);
expect(result).toHaveProperty("author", "Founders Fund");
expect(result).not.toHaveProperty("author");
});
});

Expand Down
8 changes: 4 additions & 4 deletions src/parser/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/parser/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down