web/utils/articles.js

29 lines
719 B
JavaScript
Raw Permalink Normal View History

2023-12-20 23:14:44 +01:00
import { parseFeed } from "https://deno.land/x/rss/mod.ts";
import * as cheerio from "https://esm.sh/cheerio@1.0.0-rc.12";
2024-01-31 01:57:12 +01:00
const resp = await fetch(
"https://mirror.xyz/0x0f1F3DAf416B74DB3DE55Eb4D7513a80F4841073/feed/atom",
);
const xml = await resp.text();
const feed = await parseFeed(xml);
2023-12-20 23:14:44 +01:00
2024-01-31 01:57:12 +01:00
const articles = [];
2023-12-20 23:14:44 +01:00
for (const entry of feed.entries) {
2024-01-31 01:57:12 +01:00
//console.log(entry)
2023-12-20 23:14:44 +01:00
2024-01-31 01:57:12 +01:00
const $ = cheerio.load(entry.content.value);
articles.push({
url: entry.id,
title: entry.title.value,
img: $("img").attr("src"),
date: entry.updated,
});
2023-12-20 23:14:44 +01:00
}
//console.log(articles)
2024-01-31 01:57:12 +01:00
await Deno.writeTextFile(
"./src/articles.json",
JSON.stringify(articles, null, 2),
);
console.log(`File ./src/articles.json saved`);