rsshub
Version:
Make RSS Great Again!
47 lines (46 loc) • 1.62 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 { t as InvalidParameterError } from "./invalid-parameter-CGxhjomn.mjs";
import { t as isValidHost } from "./valid-host-BhcFf8dN.mjs";
import { load } from "cheerio";
//#region lib/routes/fashionnetwork/headline.ts
const route = {
path: "/headline/:country?",
categories: ["new-media"],
example: "/fashionnetwork/headline",
parameters: { country: "Country, see the News route below, `ww` by default" },
name: "Headline",
maintainers: ["nczitzk"],
handler
};
async function handler(ctx) {
const { country = "ww" } = ctx.req.param();
if (!isValidHost(country)) throw new InvalidParameterError("Invalid country");
const rootUrl = `https://${country}.fashionnetwork.com`;
const $ = load(await rofetch(rootUrl));
const list = $(".point-carousel__item").slice(5, 10).toArray().map((item) => {
const $item = $(item);
const a = $item.find(".family-title a");
return {
title: a.text(),
link: `${rootUrl}${a.attr("href")}`,
pubDate: parseDate($item.find(".time-ago").attr("data-value"))
};
});
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const content = load(await rofetch(item.link));
content(".newsTitle, .ads").remove();
return {
...item,
description: content("div[itemprop=\"text\"]").html()
};
})));
return {
title: `${$(".category-label").eq(0).text()} - FashionNetwork`,
link: rootUrl,
item: items
};
}
//#endregion
export { route };