Skip to content

Commit

Permalink
Refactor XML rendering URL and sort episodes by date
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilan-riviere committed Oct 4, 2024
1 parent e10ac5d commit d2deb59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/models/Podcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export class Podcast {
) {}

public static make(feedUrl: string, channel: Channel, lang: string = 'en'): Podcast {
const xmlRenderUrl = route('/api/render', { query: { url: feedUrl, format: 'xml' } })
// http://localhost:3000/api/xml?url=http://zqsd.fr/zqsd.xml
const xmlRenderUrl = route('/api/xml', { query: { url: feedUrl } })
const self = new this(feedUrl, xmlRenderUrl)

self.title = channel.title
Expand Down Expand Up @@ -89,6 +90,14 @@ export class Podcast {
self.episodes?.push(Episode.make(item, self.lang))
})

// sort episodes by date
self.episodes?.sort((a, b) => {
if (a.pubDate && b.pubDate) {
return new Date(b.pubDate).getTime() - new Date(a.pubDate).getTime()
}
return 0
})

return self
}

Expand Down
3 changes: 2 additions & 1 deletion src/services/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ export class Parser {
const base64 = atob(self.url)
self.url = base64
}
// eslint-disable-next-line unused-imports/no-unused-vars
catch (error) {
console.error(error)
// console.error(error)
}

const res = await self.fetch()
Expand Down

0 comments on commit d2deb59

Please sign in to comment.