centralizar manejo de feeds
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Cat /dev/Nulo 2023-04-16 20:40:10 -03:00
parent bd3a15cd46
commit 4c0b0bb173
3 changed files with 30 additions and 19 deletions

View file

@ -4,13 +4,7 @@ import { parseFeed as _parseFeed } from "htmlparser2";
import { a, li, raw, render, ul } from "@nulo/html.js"; import { a, li, raw, render, ul } from "@nulo/html.js";
import { parseDocument } from "htmlparser2"; import { parseDocument } from "htmlparser2";
import { getElementsByTagName } from "domutils"; import { getElementsByTagName } from "domutils";
import { feeds, readFeed } from "./feeds";
const feeds = {
fauno: "https://fauno.endefensadelsl.org/feed.xml",
copiona: "https://copiona.com/feed.xml",
j3s: "https://j3s.sh/feed.atom",
icyphox: "https://icyphox.sh/blog/feed.xml",
};
export default async () => { export default async () => {
const articles = []; const articles = [];
@ -22,10 +16,7 @@ export default async () => {
*/ */
const relativeLink = (link) => new URL(link, baseUrl).toString(); const relativeLink = (link) => new URL(link, baseUrl).toString();
const rawFeed = await readFile( const rawFeed = await readFeed(name);
path.join("cached-feeds/", name + ".xml"),
"utf-8"
);
const { title, item, link } = parseFeed(rawFeed); const { title, item, link } = parseFeed(rawFeed);
articles.push( articles.push(

27
feeds.js Normal file
View file

@ -0,0 +1,27 @@
import { readFile, writeFile } from "fs/promises";
import { join } from "path";
export const feeds = {
fauno: "https://fauno.endefensadelsl.org/feed.xml",
copiona: "https://copiona.com/feed.xml",
j3s: "https://j3s.sh/feed.atom",
icyphox: "https://icyphox.sh/blog/feed.xml",
};
if (process.argv[2] === "refresh") {
for (const [name, url] of Object.entries(feeds)) {
console.log(`Refreshing ${name}`);
const res = await fetch(url);
const txt = await res.text();
await writeFile(join("cached-feeds/", `${name}.xml`), txt);
}
}
/**
* Lee un feed ya cacheado sin parsear.
* @param {string} name
* @returns string
*/
export async function readFeed(name) {
return await readFile(join("cached-feeds/", name + ".xml"), "utf-8");
}

9
tool
View file

@ -11,15 +11,8 @@ build() {
check() { check() {
./node_modules/.bin/tsc --noEmit || exit $? ./node_modules/.bin/tsc --noEmit || exit $?
} }
refresh_feed() {
echo "Refreshing $1"
wget -qO "cached-feeds/$1.xml" "$2" || exit $?
}
refresh_feeds() { refresh_feeds() {
refresh_feed fauno https://fauno.endefensadelsl.org/feed.xml node feeds.js refresh
refresh_feed copiona https://copiona.com/feed.xml
refresh_feed j3s https://j3s.sh/feed.atom
refresh_feed icyphox https://icyphox.sh/blog/feed.xml
} }
fatal() { fatal() {