feat: loose self rss check
This commit is contained in:
parent
f94bdfcf55
commit
7cbcd059c6
|
|
@ -22,6 +22,7 @@
|
|||
"async-lock": "^1.4.0",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"clsx": "^2.0.0",
|
||||
"he": "1.2.0",
|
||||
"lodash": "^4.17.21",
|
||||
"lucide-react": "^0.298.0",
|
||||
"md5.js": "^1.3.5",
|
||||
|
|
@ -32,7 +33,6 @@
|
|||
"react-hot-toast": "^2.4.1",
|
||||
"react-router-dom": "^6.21.0",
|
||||
"route-recognizer": "^0.3.4",
|
||||
"rss-parser": "^3.13.0",
|
||||
"tailwind-merge": "^2.1.0",
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
"usehooks-ts": "^2.9.1"
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@ dependencies:
|
|||
clsx:
|
||||
specifier: ^2.0.0
|
||||
version: 2.0.0
|
||||
he:
|
||||
specifier: 1.2.0
|
||||
version: 1.2.0
|
||||
lodash:
|
||||
specifier: ^4.17.21
|
||||
version: 4.17.21
|
||||
|
|
@ -65,9 +68,6 @@ dependencies:
|
|||
route-recognizer:
|
||||
specifier: ^0.3.4
|
||||
version: 0.3.4
|
||||
rss-parser:
|
||||
specifier: ^3.13.0
|
||||
version: 3.13.0
|
||||
tailwind-merge:
|
||||
specifier: ^2.1.0
|
||||
version: 2.1.0
|
||||
|
|
@ -4452,6 +4452,11 @@ packages:
|
|||
dependencies:
|
||||
function-bind: 1.1.2
|
||||
|
||||
/he@1.2.0:
|
||||
resolution: {integrity: sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==}
|
||||
hasBin: true
|
||||
dev: false
|
||||
|
||||
/htmlnano@2.1.0(postcss@8.4.32)(svgo@2.8.0)(typescript@5.2.2):
|
||||
resolution: {integrity: sha512-jVGRE0Ep9byMBKEu0Vxgl8dhXYOUk0iNQ2pjsG+BcRB0u0oDF5A9p/iBGMg/PGKYUyMD0OAGu8dVT5Lzj8S58g==}
|
||||
peerDependencies:
|
||||
|
|
@ -6080,13 +6085,6 @@ packages:
|
|||
resolution: {integrity: sha512-2+MhsfPhvauN1O8KaXpXAOfR/fwe8dnUXVM+xw7yt40lJRfPVQxV6yryZm0cgRvAj5fMF/mdRZbL2ptwbs5i2g==}
|
||||
dev: false
|
||||
|
||||
/rss-parser@3.13.0:
|
||||
resolution: {integrity: sha512-7jWUBV5yGN3rqMMj7CZufl/291QAhvrrGpDNE4k/02ZchL0npisiYYqULF71jCEKoIiHvK/Q2e6IkDwPziT7+w==}
|
||||
dependencies:
|
||||
entities: 2.2.0
|
||||
xml2js: 0.5.0
|
||||
dev: false
|
||||
|
||||
/run-async@3.0.0:
|
||||
resolution: {integrity: sha512-540WwVDOMxA6dN6We19EcT9sc3hkXPw5mzRNGM3FkdN/vtE9NFvj5lFAPNwUDmJjXidm3v7TC1cTE7t17Ulm1Q==}
|
||||
engines: {node: '>=0.12.0'}
|
||||
|
|
@ -6124,6 +6122,7 @@ packages:
|
|||
resolution: {integrity: sha512-0s+oAmw9zLl1V1cS9BtZN7JAd0cW5e0QH4W3LWEK6a4LaLEA2OTpGYWDY+6XasBLtz6wkm3u1xRw95mRuJ59WA==}
|
||||
requiresBuild: true
|
||||
dev: false
|
||||
optional: true
|
||||
|
||||
/scheduler@0.23.0:
|
||||
resolution: {integrity: sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==}
|
||||
|
|
@ -6762,19 +6761,6 @@ packages:
|
|||
/wrappy@1.0.2:
|
||||
resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==}
|
||||
|
||||
/xml2js@0.5.0:
|
||||
resolution: {integrity: sha512-drPFnkQJik/O+uPKpqSgr22mpuFHqKdbS835iAQrUC73L2F5WkboIRd63ai/2Yg6I1jzifPFKH2NTK+cfglkIA==}
|
||||
engines: {node: '>=4.0.0'}
|
||||
dependencies:
|
||||
sax: 1.3.0
|
||||
xmlbuilder: 11.0.1
|
||||
dev: false
|
||||
|
||||
/xmlbuilder@11.0.1:
|
||||
resolution: {integrity: sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==}
|
||||
engines: {node: '>=4.0'}
|
||||
dev: false
|
||||
|
||||
/xxhash-wasm@0.4.2:
|
||||
resolution: {integrity: sha512-/eyHVRJQCirEkSZ1agRSCwriMhwlyUcFkXD5TPVSLP+IPzjsqMVzZwdoczLp1SoQU0R3dxz1RpIK+4YNQbCVOA==}
|
||||
dev: false
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
import RSSParser from "rss-parser"
|
||||
import type { RSSData } from "./types"
|
||||
|
||||
const rssParser = new RSSParser()
|
||||
import { parseRSS } from "./utils"
|
||||
|
||||
export async function getPageRSS(data: {
|
||||
html: string
|
||||
|
|
@ -54,27 +52,17 @@ export async function getPageRSS(data: {
|
|||
}
|
||||
|
||||
if (html) {
|
||||
let feed
|
||||
try {
|
||||
feed = await rssParser.parseString(html)
|
||||
console.log("feed", feed)
|
||||
} catch (error) {}
|
||||
if (feed) {
|
||||
const result = parseRSS(html)
|
||||
if (result) {
|
||||
pageRSS.push({
|
||||
url: location.href,
|
||||
title: feed.title,
|
||||
title: result.title,
|
||||
image
|
||||
});
|
||||
} else {
|
||||
pageRSS.push({
|
||||
url: location.href,
|
||||
title: "",
|
||||
image
|
||||
});
|
||||
}
|
||||
|
||||
// skip the following check if this page is an RSS feed
|
||||
return pageRSS
|
||||
// skip the following check if this page is an RSS feed
|
||||
return pageRSS
|
||||
}
|
||||
}
|
||||
|
||||
// head links
|
||||
|
|
@ -165,10 +153,14 @@ export async function getPageRSS(data: {
|
|||
const content = await (await fetch(feed.url, {
|
||||
mode: "no-cors",
|
||||
})).text()
|
||||
const result = await rssParser.parseString(content)
|
||||
feed.title = result.title;
|
||||
pageRSS.push(feed);
|
||||
unique.save(feed.url)
|
||||
const result = parseRSS(content)
|
||||
if (result) {
|
||||
if (result.title) {
|
||||
feed.title = result.title;
|
||||
}
|
||||
pageRSS.push(feed);
|
||||
unique.save(feed.url)
|
||||
}
|
||||
resolve()
|
||||
} catch (error) {
|
||||
resolve()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { type ClassValue, clsx } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
import he from "he"
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
|
|
@ -13,4 +14,15 @@ export function removeFunctionFields(obj) {
|
|||
removeFunctionFields(obj[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
export function parseRSS(content: string) {
|
||||
if (content.includes("<rss ")) {
|
||||
const titleContent = content.match(/<title>(.*)<\/title>/)?.[1]
|
||||
const title = titleContent ? he.decode(titleContent)?.replace(/<!\[CDATA\[(.*)]]>/, (match, p1) => p1)?.trim() : ""
|
||||
return {
|
||||
title,
|
||||
}
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue