Skip to content

Commit

Permalink
WIP: rss generation
Browse files Browse the repository at this point in the history
  • Loading branch information
olaven committed Jan 19, 2021
1 parent 75b73df commit 78b3c0f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/common/src/test/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const credentials = (): models.UserCredentials => ({
});

export const article = (): models.Article => ({
title: faker.hacker.phrase(),
original_url: faker.internet.url(),
text: faker.lorem.paragraphs(15),
owner_id: faker.random.uuid(),
Expand Down
42 changes: 38 additions & 4 deletions packages/converter/src/helpers/rss.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,50 @@
import { test } from "@paperpod/common";
import { convertToRSS } from "../converter";
import { articleToRSSItem } from "./rss";
import { hasUncaughtExceptionCaptureCallback } from "process";
import { serialize } from "serialize-xml";
import { convertToRSSFeed, toItemTag } from "./rss";


describe("Conversion from articles to RSS", () => {

describe("Converting a single article", () => {
const serializeItem = (article = test.mocks.article()) =>
serialize(
toItemTag(article)
)

describe("Converting article to single item", () => {

it("Does not throw", () => {

const article = test.mocks.article();
expect(() => { articleToRSSItem(article) }).not.toThrow();
expect(() => { toItemTag(article) }).not.toThrow();
});

it("Does contain title", () => {

const item = serializeItem();
expect(item.includes("<title>")).toBeTruthy();
});

it("Does contain the same title as the article", () => {

const article = test.mocks.article();
expect(article.title).toBeDefined();
const rss = serializeItem(article);
console.log("HERE IS RSS", rss);
expect(rss.includes(`<title>${article.title}</title>`)).toBeTruthy();
});
});

describe("Converting list of articles to feed", () => {


it("Does return something looking like RSS", () => {

const rss = convertToRSSFeed([]);
console.log(`RSS HERE ${rss}`);
expect(rss.includes('<rss version="2.0">')).toBe(true);
expect(rss.includes("<channel>")).toBe(true);
expect(rss.includes("<link>")).toBe(true);
});
})
});
38 changes: 28 additions & 10 deletions packages/converter/src/helpers/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,40 @@

import { serialize, tag, declaration } from "serialize-xml";
import { models } from "@paperpod/common";
export const articleToRSSItem = (article: models.Article) => {

const xml = serialize(
export const convertToRSSFeed = (articles: models.Article[]) =>
serialize(
tag("rss", [
tag("channel", [
tag("title", "Paperpod Feed"),
tag("link", "LINK TO FEED"),
tag("description", "This is your Paperpod Feed. Thanks for using Paperpod! Send articles, and they will appear here"),
tag("ttl", "60"), //60 minutes
tag("image", [
tag("url", "https://paperpod.fm/logo.svg"), //TODO: image that's friendly for podcast players
tag("link", "LINK TO FEED"),
tag("title", "Paperpod Feed")
])]
//TODO: items (should be done here, what's implemented above should be done somewhere with access to all articles)
toImageTag(),
...articles.map(toItemTag)
],
)],
[["version", "2.0"]]
))
}
),
)

export const toImageTag = () =>
tag("image", [
tag("url", "https://paperpod.fm/logo.svg"), //TODO: image that's friendly for podcast players
tag("link", "LINK TO FEED"),
tag("title", "Paperpod Feed")
]);

export const toItemTag = (article: models.Article) =>
tag(
"item",
[
tag("title", article.title),
tag("link", "FIXME: some value herer"),
tag("description", "FIXME: some value herer"),
tag("source ", "FIXME: some value herer"),
tag("guid", "FIXME: some value herer"),
tag("pubDate", "FIXME: some value herer"),
tag("author", "FIXME: some value herer"),
]
)

0 comments on commit 78b3c0f

Please sign in to comment.