mirror of
https://github.com/yang991178/fluent-reader.git
synced 2025-02-01 01:47:07 +01:00
parent
f3aac967eb
commit
27c81788e7
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
||||
dist/article/article.js text eol=lf
|
@ -30,7 +30,9 @@
|
||||
"log": {
|
||||
"empty": "No notifications",
|
||||
"fetchFailure": "Failed to load source \"{name}\".",
|
||||
"fetchSuccess": "Successfully fetched {count, plural, =1 {# article} other {# articles}}."
|
||||
"fetchSuccess": "Successfully fetched {count, plural, =1 {# article} other {# articles}}.",
|
||||
"networkError": "A network error has occurred.",
|
||||
"parseError": "An error has occurred when parsing the XML feed."
|
||||
},
|
||||
"nav": {
|
||||
"menu": "Menu",
|
||||
@ -174,4 +176,4 @@
|
||||
"setPac": "Set PAC",
|
||||
"pacHint": "For Socks proxies, it is recommended for PAC to return \"SOCKS5\" for proxy-side DNS. Turning off proxy requires restart."
|
||||
}
|
||||
}
|
||||
}
|
@ -30,7 +30,9 @@
|
||||
"log": {
|
||||
"empty": "无消息",
|
||||
"fetchFailure": "无法加载订阅源“{name}”",
|
||||
"fetchSuccess": "成功加载 {count} 篇文章"
|
||||
"fetchSuccess": "成功加载 {count} 篇文章",
|
||||
"networkError": "连接订阅源时出错",
|
||||
"parseError": "解析XML信息流时出错"
|
||||
},
|
||||
"nav": {
|
||||
"menu": "菜单",
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as db from "../db"
|
||||
import { SourceActionTypes, INIT_SOURCES, ADD_SOURCE, DELETE_SOURCE } from "./source"
|
||||
import { ItemActionTypes, FETCH_ITEMS, RSSItem, MARK_READ, MARK_UNREAD, TOGGLE_STARRED, TOGGLE_HIDDEN, applyItemReduction, ItemState } from "./item"
|
||||
import { ItemActionTypes, FETCH_ITEMS, RSSItem, MARK_READ, MARK_UNREAD, TOGGLE_STARRED, TOGGLE_HIDDEN, applyItemReduction, ItemState, MARK_ALL_READ } from "./item"
|
||||
import { ActionStatus, AppThunk, mergeSortedArrays } from "../utils"
|
||||
import { PageActionTypes, SELECT_PAGE, PageType, APPLY_FILTER } from "./page"
|
||||
|
||||
|
@ -2,7 +2,7 @@ import * as db from "../db"
|
||||
import intl from "react-intl-universal"
|
||||
import { domParser, htmlDecode, ActionStatus, AppThunk } from "../utils"
|
||||
import { RSSSource } from "./source"
|
||||
import { FeedActionTypes, INIT_FEED, LOAD_MORE } from "./feed"
|
||||
import { FeedActionTypes, INIT_FEED, LOAD_MORE, FilterType, initFeeds } from "./feed"
|
||||
import Parser from "@yang991178/rss-parser"
|
||||
|
||||
export class RSSItem {
|
||||
@ -38,19 +38,17 @@ export class RSSItem {
|
||||
item.content = parsed.content || ""
|
||||
item.snippet = htmlDecode(parsed.contentSnippet || "")
|
||||
}
|
||||
if (parsed.thumb) item.thumb = parsed.thumb
|
||||
else if (parsed.image) {
|
||||
if (parsed.image.$ && parsed.image.$.url) {
|
||||
item.thumb = parsed.image.$.url
|
||||
} else if (typeof parsed.image === "string") {
|
||||
item.thumb = parsed.image
|
||||
}
|
||||
}
|
||||
else if (parsed.mediaContent) {
|
||||
if (parsed.thumb) {
|
||||
item.thumb = parsed.thumb
|
||||
} else if (parsed.image && parsed.image.$ && parsed.image.$.url) {
|
||||
item.thumb = parsed.image.$.url
|
||||
} else if (parsed.image && typeof parsed.image === "string") {
|
||||
item.thumb = parsed.image
|
||||
} else if (parsed.mediaContent) {
|
||||
let images = parsed.mediaContent.filter(c => c.$ && c.$.medium === "image" && c.$.url)
|
||||
if (images.length > 0) item.thumb = images[0].$.url
|
||||
}
|
||||
if(!item.thumb) {
|
||||
if (!item.thumb) {
|
||||
let dom = domParser.parseFromString(item.content, "text/html")
|
||||
let baseEl = dom.createElement('base')
|
||||
baseEl.setAttribute('href', item.link.split("/").slice(0, 3).join("/"))
|
||||
@ -58,6 +56,9 @@ export class RSSItem {
|
||||
let img = dom.querySelector("img")
|
||||
if (img && img.src) item.thumb = img.src
|
||||
}
|
||||
if (item.thumb && !item.thumb.startsWith("https:") && !item.thumb.startsWith("http:")) {
|
||||
delete item.thumb
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,7 +66,7 @@ export type ItemState = {
|
||||
[_id: string]: RSSItem
|
||||
}
|
||||
|
||||
export const FETCH_ITEMS = 'FETCH_ITEMS'
|
||||
export const FETCH_ITEMS = "FETCH_ITEMS"
|
||||
export const MARK_READ = "MARK_READ"
|
||||
export const MARK_ALL_READ = "MARK_ALL_READ"
|
||||
export const MARK_UNREAD = "MARK_UNREAD"
|
||||
@ -223,8 +224,8 @@ export function markRead(item: RSSItem): AppThunk {
|
||||
|
||||
export function markAllRead(sids: number[] = null): AppThunk {
|
||||
return (dispatch, getState) => {
|
||||
let state = getState()
|
||||
if (sids === null) {
|
||||
let state = getState()
|
||||
let feed = state.feeds[state.page.feedId]
|
||||
sids = feed.sids
|
||||
}
|
||||
@ -235,6 +236,9 @@ export function markAllRead(sids: number[] = null): AppThunk {
|
||||
}
|
||||
})
|
||||
dispatch(markAllReadDone(sids))
|
||||
if (!(state.page.filter.type & FilterType.ShowRead)) {
|
||||
dispatch(initFeeds(true))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import intl from "react-intl-universal"
|
||||
import { ThunkAction, ThunkDispatch } from "redux-thunk"
|
||||
import { AnyAction } from "redux"
|
||||
import { RootState } from "./reducer"
|
||||
@ -27,15 +28,20 @@ const rssParser = new Parser({
|
||||
})
|
||||
|
||||
export async function parseRSS(url: string) {
|
||||
let result: Response
|
||||
try {
|
||||
let result = await fetch(url, { credentials: "omit" })
|
||||
if (result.ok) {
|
||||
return await rssParser.parseString(await result.text())
|
||||
} else {
|
||||
throw new Error(result.statusText)
|
||||
}
|
||||
result = await fetch(url, { credentials: "omit" })
|
||||
} catch {
|
||||
throw new Error("A network error has occurred.")
|
||||
throw new Error(intl.get("log.networkError"))
|
||||
}
|
||||
if (result && result.ok) {
|
||||
try {
|
||||
return await rssParser.parseString(await result.text())
|
||||
} catch {
|
||||
throw new Error(intl.get("log.parseError"))
|
||||
}
|
||||
} else {
|
||||
throw new Error(result.statusText)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user