rsshub
Version:
Make RSS Great Again!
53 lines (52 loc) • 2.17 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";
//#region lib/routes/yahoo/author.ts
const route = {
path: "/author/:author",
categories: ["traditional-media"],
example: "/yahoo/author/hannah-keyser",
parameters: { author: "Author" },
name: "News By Author",
maintainers: ["loganrockmore"],
description: "Provides all of the articles by the specified Yahoo! author.",
handler
};
async function handler(ctx) {
const { author } = ctx.req.param();
const response = await rofetch.raw(`https://www.yahoo.com/author/${author}/`);
const url = response.url;
const $ = load(response._data);
const title = $("meta[property=\"og:title\"]").attr("content") ?? "";
const description = $("meta[property=\"og:description\"]").attr("content");
const list = $("script[type=\"application/ld+json\"]").toArray().map((item) => JSON.parse($(item).text())).find((data) => data.hasPart?.mainEntity?.itemListElement).hasPart.mainEntity.itemListElement.slice(0, 10).map((item) => ({ link: item.url }));
return {
title,
link: url,
description,
item: await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const content = load(await rofetch(item.link));
content("button").remove();
const cover = content("div.story-cover");
cover.find("img").removeAttr("style");
const body = content("div.content-body");
body.find("div.sda-placeholder-txt, div.bodyad-wrapper, div.content-videowrapper, .consent").remove();
content("div.story-cover img, div.content-body img").each((_, img) => {
const src = content(img).attr("src");
if (src?.startsWith("https://s.yimg.com/lo/mysterio/")) {
content(img).attr("src", decodeURIComponent(src.split("/").at(-1)));
content(img).siblings("source").remove();
}
});
return {
...item,
title: content("meta[property=\"og:title\"]").attr("content"),
description: (cover.html() ?? "") + body.html(),
pubDate: parseDate(content("time").attr("datetime"))
};
})))
};
}
//#endregion
export { route };