Skip to content

Commit

Permalink
WIP: Rss + test setup in converter
Browse files Browse the repository at this point in the history
  • Loading branch information
olaven committed Jan 19, 2021
1 parent 4bbec13 commit 91284bb
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/converter/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
modulePathIgnorePatterns: ["<rootDir>/dist/"]
};
5 changes: 4 additions & 1 deletion packages/converter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"version": "0.0.1",
"main": "./dist/index.js",
"scripts": {
"build": "tsc"
"build": "tsc",
"test": "jest --detectOpenHandles"
},
"dependencies": {
"@google-cloud/text-to-speech": "^3.1.3",
Expand All @@ -16,6 +17,8 @@
},
"devDependencies": {
"@types/node": "^14.14.14",
"jest": "^26.6.3",
"ts-jest": "^26.4.4",
"typescript": "^4.1.3"
}
}
5 changes: 3 additions & 2 deletions packages/converter/src/converter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { models, server } from "@paperpod/common";
import { textToAudio, articleToRssEntry, getTextualData } from "./helpers/helpers";
import { textToAudio, articleToRSSItem, getTextualData } from "./helpers/helpers";


/**
Expand Down Expand Up @@ -43,6 +43,7 @@ export const convertToText =
*/
export const convertToRSS = (articles: models.Article[]) => {

const entires = articles.map(articleToRssEntry);
const entires = articles.map(articleToRSSItem);

//FIXME: implement
}
16 changes: 16 additions & 0 deletions packages/converter/src/helpers/rss.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { test } from "@paperpod/common";
import { convertToRSS } from "../converter";
import { articleToRSSItem } from "./rss";


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

describe("Converting a single article", () => {

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

const article = test.mocks.article();
expect(() => { articleToRSSItem(article) }).not.toThrow();
});
})
});
44 changes: 41 additions & 3 deletions packages/converter/src/helpers/rss.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,45 @@
import { serialize, tag, declaration } from "serialize-xml";
import { models } from "@paperpod/common";
export const articleToRssEntry = (article: models.Article) => {
/*
* `<rss version="2.0"></rss>` X
* `<channel></channel>`
* `<title></title>`
* `<link></link>`
* `<description></description>`
* `<ttl></ttl>` - hvor lang tid skal det gå før man oppdaterer
* `<image></image>`
* `<url></url>`
* `<title></title>` (i praksis alltid samme verdi som channel.title)
* `<link></link>` (i praksis alltid samme verdi som channel.link)
* `<item></item>` - gjenta for hvert `<item>`. OBS: er ikke childs, men siblings av alt over
* `<title></title>` - tittelen for dette elementet
* `<link></link>` - linken til innholdet
* `<description></description>` - beskrivelsen
* `<source url="<SOME_URL>"></source>` - hvilken feed elementet kommer fra
* `<guid></guid>` - ID For elementet
* `<pubDate></pubDate>` - [format](https://www.ietf.org/rfc/rfc822.txt)
* `<author></author>` - den som har laget elementet (f.eks artikkel for [[paeprpod]])
*/

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

const xml = 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)
)],
[["version", "2.0"]]
))
}

0 comments on commit 91284bb

Please sign in to comment.