Skip to content

Commit

Permalink
Merge pull request #13 from chezhe/master
Browse files Browse the repository at this point in the history
optimize rss.xml parser
  • Loading branch information
chezhe authored Jun 24, 2022
2 parents e99bacb + 36cc02a commit 619b156
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aleph"
version = "0.6.0"
version = "0.7.0"
description = "A Tauri App"
authors = ["chezhe"]
license = ""
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"package": {
"productName": "aleph",
"version": "0.6.0"
"version": "0.7.0"
},
"build": {
"distDir": "../build",
Expand Down
4 changes: 0 additions & 4 deletions src/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,3 @@ export const stripURL = (url?: string) => {
}
return result
}

// export const diffConcat = (a: Episode[], b: Episode[]) => {

// }
38 changes: 29 additions & 9 deletions src/utils/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ export async function fetchFeed(feed: Feed): Promise<Feed[]> {
const extra = {
image: jObj.rss?.channel?.image,
}
return (
jObj.rss?.channel?.item.map((item: any) =>
formatEpisode(item, feed, extra)
) || []
)

let items = []
if (Array.isArray(jObj?.feed?.entry)) {
items = jObj?.feed?.entry
} else if (Array.isArray(jObj.rss?.channel?.item)) {
items = jObj.rss?.channel?.item
}
console.log('fetchFeed', items)

return items.map((item: any) => formatEpisode(item, feed, extra))
})
.catch((err) => {
console.log(err)
Expand Down Expand Up @@ -94,16 +99,31 @@ export function formatEpisode(
cover = newItem.image.url || newItem.image['@_href'] || ''
}

const link = `${newItem.link}?${guid}`
let link = ''
if (typeof newItem.link === 'string') {
link = `${newItem.link}?${guid}`
} else {
link = newItem.id || newItem.link['@_href']
}

let author = ''
if (newItem.author) {
author = newItem.author.name ?? (newItem.author || newItem['itunes:author'])
}

let description = newItem['content:encoded'] || newItem.description || ''
if (newItem.content) {
description = newItem.content['#text']
}

newItem = {
link,
author: newItem.author || newItem['itunes:author'] || '',
pubDate: newItem.pubDate || '',
author,
pubDate: newItem.pubDate || newItem.published || '',
cover,
podurl,
title: newItem.title || '',
description: newItem['content:encoded'] || newItem.description || '',
description,
guid: guid || '',
feedid: feed.id,
readed: false,
Expand Down

0 comments on commit 619b156

Please sign in to comment.