Feature/types #4

Merged
augustskare merged 2 commits from feature/types into main 2023-03-11 09:46:56 +00:00
1 changed files with 18 additions and 13 deletions
Showing only changes of commit b65fb9e3b6 - Show all commits

View File

@ -1,17 +1,18 @@
import { nrkRadio, Serie, Episode } from "../../../lib/nrk.ts" import { nrkRadio, Episode } from "../../../lib/nrk.ts"
import { HandlerContext } from "$fresh/server.ts"; import { HandlerContext } from "$fresh/server.ts";
import { serialize, tag, declaration } from "https://deno.land/x/serializexml@v0.3.2/mod.ts"; import { serialize, tag, declaration } from "https://deno.land/x/serializexml@v0.3.2/mod.ts";
function toItemTag(episode: Episode) { function toItemTag(episode: Episode) {
const description = episode.titles.description || episode.titles.subtitle; const description = episode.titles.subtitle || "";
return tag("item", [ return tag("item", [
tag("title", episode.titles.title), tag("title", episode.titles.title),
tag("link", episode.url), tag("link", episode.url),
tag("description", description), tag("description", description),
tag("itunes:summary", description), tag("itunes:summary", description),
tag("guid", episode.id, [["isPermaLink", "false"]]), tag("guid", episode.id, [["isPermaLink", "false"]]),
tag("pubDate", episode.date), tag("pubDate", new Date(episode.date).toUTCString()),
tag("itunes:duration", episode.durationInSeconds.toString()),
tag("enclosure", "", [ tag("enclosure", "", [
["url", episode.url], ["url", episode.url],
["length", episode.durationInSeconds.toString()], ["length", episode.durationInSeconds.toString()],
@ -20,8 +21,9 @@ function toItemTag(episode: Episode) {
]) ])
} }
async function buildFeed(seriesId: any) { async function buildFeed(seriesId: string) {
const serie = await nrkRadio.getSerieData(seriesId) const serie = await nrkRadio.getSerieData(seriesId)
const imageUrl = serie.squareImage.at(-1)?.url;
// Quickly adapted from https://raw.githubusercontent.com/olaven/paperpod/1cde9abd3174b26e126aa74fc5a3b63fd078c0fd/packages/converter/src/rss.ts // Quickly adapted from https://raw.githubusercontent.com/olaven/paperpod/1cde9abd3174b26e126aa74fc5a3b63fd078c0fd/packages/converter/src/rss.ts
return serialize( return serialize(
@ -33,20 +35,23 @@ async function buildFeed(seriesId: any) {
"rss", "rss",
[ [
tag("channel", [ tag("channel", [
tag("title", serie.title), tag("title", serie.titles.title),
tag("link", `https://radio.nrk.no/podkast/${serie.id}`), tag("link", `https://radio.nrk.no/podkast/${serie.id}`),
tag("itunes:author", "NRK"),
tag( tag(
"description", "description",
serie.subtitle serie.titles.subtitle || ""
), ),
tag("ttl", "60"), //60 minutes tag("ttl", "60"), //60 minutes
tag("itunes:image", "", [ ...(imageUrl ? [
["href", serie.image.url], tag("itunes:image", "", [
]), ["href", imageUrl],
tag("image", [ ]),
tag("url", serie.image.url), tag("image", [
tag("title", serie.title), tag("url", imageUrl),
]), tag("title", serie.titles.title),
])
] : []),
...serie.episodes.map(toItemTag), ...serie.episodes.map(toItemTag),
]), ]),
], ],