rsshub
Version:
Make RSS Great Again!
66 lines (64 loc) • 2.19 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { load } from "cheerio";
import Parser from "rss-parser";
//#region lib/routes/chinafile/index.ts
const route = {
path: "/:category?",
categories: ["new-media"],
example: "/chinafile/all",
parameters: { category: "Category, by default `all`" },
name: "Reporting & Opinion",
maintainers: ["oppilate"],
description: `Generates full-text feeds that the official feed doesn't provide.
| All | The China NGO Project |
| --- | --------------------- |
| all | ngo |`,
handler
};
async function handler(ctx) {
const { category = "all" } = ctx.req.param();
const rssUrl = `https://feeds.feedburner.com/chinafile/${category}`;
const language = "en-us";
const icon = "https://www.chinafile.com/sites/default/files/chinafile_favicon.png";
const logo = "https://www.chinafile.com/sites/all/themes/cftwo/assets/images/logos/logo-large.png";
const feed = await new Parser().parseURL(rssUrl);
const items = await Promise.all(feed.items.map((item) => cache_default.tryGet(item.link, async () => {
const $ = load(await rofetch(item.link));
const content = $("article");
const cover = $(".view-featured-photo");
if (cover.length > 0) {
cover.insertBefore(content[0].childNodes[0]);
cover.remove();
}
const summary = $("meta[name=\"description\"]").attr("content");
const updatedAt = $("meta[property=\"og:updated_time\"]").attr("content");
const categories = $("meta[property=\"article:tag\"]").toArray().map((el) => $(el).attr("content"));
const url = $("link[rel=\"canonical\"]").attr("href");
return {
title: item.title,
id: item.guid,
pubDate: parseDate(item.pubDate.replace(" - ", " ").replace("am", " am").replace("pm", " pm")),
updated: updatedAt,
author: item.creator,
link: url,
summary,
description: content.html(),
category: categories,
icon,
logo
};
})));
return {
title: feed.title,
link: feed.link,
description: feed.description,
item: items,
language,
icon,
logo
};
}
//#endregion
export { route };