Skip to content

Commit

Permalink
feat: check links prefixed with feed:
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Dec 17, 2023
1 parent fd3be69 commit 2679d79
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/lib/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ export async function getPageRSS(data: {
location.origin + "/favicon.ico"

function handleUrl(url) {
return new URL(url.replace(/^(feed:\/\/)/, "https://"), location.href).toString()
return new URL(url.replace(/^(feed:\/\/)/, "https://").replace(/^(feed:)/, ""), location.href).toString()
}

let pageRSS: RSSData[] = []
const unique = {
data: {},
save: function (url) {
this.data[url.replace(/^(https?:\/\/|feed:\/\/)/, "")] = 1
this.data[url.replace(/^(https?:\/\/|feed:\/\/|feed:)/, "")] = 1
},
check: function (url) {
return this.data[url.replace(/^(https?:\/\/|feed:\/\/)/, "")]
return this.data[url.replace(/^(https?:\/\/|feed:\/\/|feed:)/, "")]
}
}

// links
// head links
const types = [
"application/rss+xml",
"application/atom+xml",
Expand Down Expand Up @@ -78,7 +78,21 @@ export async function getPageRSS(data: {
}
}

// a
// prefixed with `feed:`
const feedEles = document.querySelectorAll("a[href^='feed:']")
feedEles.forEach((ele) => {
const feed = {
url: handleUrl(ele.getAttribute("href")),
title: ele.getAttribute("title") || defaultTitle,
image
}
if (!unique.check(feed.url)) {
pageRSS.push(feed)
unique.save(feed.url)
}
})

// normal a
const aEles = document.querySelectorAll("a")
const check = /([^a-zA-Z]|^)rss([^a-zA-Z]|$)/i
const uncertain = [];
Expand Down Expand Up @@ -108,6 +122,7 @@ export async function getPageRSS(data: {
}
}
}
console.log("uncertain", uncertain)
await Promise.all(uncertain.map((feed) => {
return new Promise<void>(async (resolve) => {
try {
Expand Down

0 comments on commit 2679d79

Please sign in to comment.