rsshub
Version:
Make RSS Great Again!
49 lines (48 loc) • 1.69 kB
JavaScript
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs";
import { t as parseDate } from "./parse-date-3kcy2Eau.mjs";
import { t as cache_default } from "./cache-C1Y-9qDV.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 response = await rofetch(rootUrl);
const $ = load(response);
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 detailResponse = await rofetch(item.link);
const content = load(detailResponse);
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 };