import { post_to_bsky } from "https://esm.town/v/fil/post_to_bsky";
import { parseFeed } from "https://esm.town/v/fil/parseFeed";
export async function bsky_rss_poll(feedUrl, storage, identifier, password) {
const entries = await parseFeed(feedUrl);
const title = unescapeHTML(entries[0].text);
const url = entries[0].link;
if (!title)
return;
const latest_rss = String(url);
if (storage[feedUrl] !== latest_rss) {
storage[feedUrl] = latest_rss;
const post = `${String(title).substring(0, 200)}${
String(title).length > 201 ? "…" : ""
}
${url} `;
return await post_to_bsky(post, identifier, password);
}
function unescapeHTML(str) {
return String(str).replace(/&|<|>|'|"/g, (tag) => ({
"&": "&",
"<": "<",
">": ">",
"'": "'",
""": '"',
}[tag] || tag)).replace(/<[^>]*>/g, "");
}
}