Mi webring.gen: brunoscheufler

This commit is contained in:
Cat /dev/Nulo 2023-05-04 09:08:13 -03:00
parent 5d8f363358
commit b4a759e436
3 changed files with 1408 additions and 6 deletions

View file

@ -17,7 +17,7 @@ export default async () => {
const relativeLink = (link) => new URL(link, baseUrl).toString(); const relativeLink = (link) => new URL(link, baseUrl).toString();
const rawFeed = await readFeed(name); const rawFeed = await readFeed(name);
const { title, item, link } = parseFeed(rawFeed); const { title, item, link } = parseFeed(baseUrl, rawFeed);
articles.push( articles.push(
li( li(
@ -42,9 +42,10 @@ export default async () => {
/** /**
* parsea un feed de rss encontrando cosas que htmlparser2 solo no encuentra * parsea un feed de rss encontrando cosas que htmlparser2 solo no encuentra
* @param {string} feedUrl
* @param {string} rawFeed * @param {string} rawFeed
*/ */
function parseFeed(rawFeed) { function parseFeed(feedUrl, rawFeed) {
const feed = _parseFeed(rawFeed); const feed = _parseFeed(rawFeed);
const item = feed?.items[0]; const item = feed?.items[0];
@ -54,7 +55,11 @@ function parseFeed(rawFeed) {
dom.childNodes, dom.childNodes,
false false
)[0]; )[0];
const linksDom = getElementsByTagName("link", feedDom.childNodes, false); const linksDom = getElementsByTagName(
(t) => ["link", "atom:link"].includes(t),
feedDom.childNodes,
false
);
const linkDom = linksDom.find( const linkDom = linksDom.find(
(d) => (d) =>
d.attribs.rel === "alternate" || d.attribs.rel === "alternate" ||
@ -62,6 +67,9 @@ function parseFeed(rawFeed) {
// >If the "rel" attribute is not present, the link element MUST be interpreted as if the link relation type is "alternate". // >If the "rel" attribute is not present, the link element MUST be interpreted as if the link relation type is "alternate".
!("rel" in d.attribs) !("rel" in d.attribs)
); );
const feedUrll = new URL(feedUrl);
const link = linkDom?.attribs?.href || feedUrll.origin;
if ( if (
!feed || !feed ||
!feed.link || !feed.link ||
@ -70,15 +78,14 @@ function parseFeed(rawFeed) {
!item.link || !item.link ||
!item.title || !item.title ||
!item.pubDate || !item.pubDate ||
!linkDom || !link
!linkDom.attribs.href
) { ) {
throw "no pude parsear"; throw "no pude parsear";
} }
return { return {
title: feed.title, title: feed.title,
link: linkDom.attribs.href, link,
item: { title: item.title, link: item.link, pubDate: item.pubDate }, item: { title: item.title, link: item.link, pubDate: item.pubDate },
}; };
} }

File diff suppressed because it is too large Load diff

View file

@ -6,6 +6,7 @@ export const feeds = {
copiona: "https://copiona.com/feed.xml", copiona: "https://copiona.com/feed.xml",
j3s: "https://j3s.sh/feed.atom", j3s: "https://j3s.sh/feed.atom",
// icyphox: "https://icyphox.sh/blog/feed.xml", // icyphox: "https://icyphox.sh/blog/feed.xml",
brunoscheufler: "https://brunoscheufler.com/rss.xml",
}; };
if (process.argv[2] === "refresh") { if (process.argv[2] === "refresh") {