This commit is contained in:
parent
bd3a15cd46
commit
4c0b0bb173
3 changed files with 30 additions and 19 deletions
|
@ -4,13 +4,7 @@ import { parseFeed as _parseFeed } from "htmlparser2";
|
|||
import { a, li, raw, render, ul } from "@nulo/html.js";
|
||||
import { parseDocument } from "htmlparser2";
|
||||
import { getElementsByTagName } from "domutils";
|
||||
|
||||
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",
|
||||
};
|
||||
import { feeds, readFeed } from "./feeds";
|
||||
|
||||
export default async () => {
|
||||
const articles = [];
|
||||
|
@ -22,10 +16,7 @@ export default async () => {
|
|||
*/
|
||||
const relativeLink = (link) => new URL(link, baseUrl).toString();
|
||||
|
||||
const rawFeed = await readFile(
|
||||
path.join("cached-feeds/", name + ".xml"),
|
||||
"utf-8"
|
||||
);
|
||||
const rawFeed = await readFeed(name);
|
||||
const { title, item, link } = parseFeed(rawFeed);
|
||||
|
||||
articles.push(
|
||||
|
|
27
feeds.js
Normal file
27
feeds.js
Normal 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
9
tool
|
@ -11,15 +11,8 @@ build() {
|
|||
check() {
|
||||
./node_modules/.bin/tsc --noEmit || exit $?
|
||||
}
|
||||
refresh_feed() {
|
||||
echo "Refreshing $1"
|
||||
wget -qO "cached-feeds/$1.xml" "$2" || exit $?
|
||||
}
|
||||
refresh_feeds() {
|
||||
refresh_feed fauno https://fauno.endefensadelsl.org/feed.xml
|
||||
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
|
||||
node feeds.js refresh
|
||||
}
|
||||
|
||||
fatal() {
|
||||
|
|
Reference in a new issue