rsshub
Version:
Make RSS Great Again!
81 lines (79 loc) • 2.89 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import path from "node:path";
import * as cheerio from "cheerio";
import { destr } from "destr";
//#region lib/routes/esquirehk/tag.ts
init_esm_shims();
const topics = new Set([
"style",
"watches",
"lifestyle",
"health",
"money-investment",
"gear",
"people",
"watch",
"mens-talk"
]);
const handler = async (ctx) => {
let { id = "Fashion" } = ctx.req.param();
id = id.toLowerCase();
const rootUrl = "https://www.esquirehk.com";
let currentUrl = `${rootUrl}/tag/${id}`;
if (topics.has(id)) currentUrl = `${rootUrl}/${id}`;
const response = await ofetch_default(currentUrl);
const $ = cheerio.load(response);
const list = [...$("div[class^=\"max-w-[100%]\"] > div > div:nth-child(2) > a").toArray().map((item) => {
item = $(item);
return {
title: item.text().trim(),
link: new URL(item.attr("href"), currentUrl).href
};
}), ...$("div.list-item > div > div:nth-child(2) > a").toArray().map((item) => {
item = $(item);
return {
title: item.text().trim(),
link: new URL(item.attr("href"), currentUrl).href
};
})].map((item) => ({
...item,
slug: item.link.replace(rootUrl, "")
})).filter((item) => !item.slug.startsWith("/campaign"));
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const response$1 = destr(await ofetch_default(`https://api.esquirehk.com${item.slug}`));
if (response$1.status === "404") return item;
item.description = response$1.intro.raw + art(path.join(__dirname, "templates/subpages-d6e0f705.art"), { subpages: response$1.subpages });
item.pubDate = parseDate(response$1.date.published, "X");
item.updated = parseDate(response$1.date.lastModified, "X");
item.author = response$1.author.name;
item.category = [...response$1.tags.topic.map((tag) => tag.name), ...response$1.tags.normal.map((tag) => tag.name)];
return item;
})));
return {
title: `${$("head title").text()} - Esquirehk`,
description: $("head meta[name=\"description\"]").attr("content"),
image: $("head meta[property=\"og:image\"]").attr("content"),
logo: $("head meta[property=\"og:image\"]").attr("content"),
link: currentUrl,
item: items
};
};
const route = {
path: "/tag/:id?",
categories: ["new-media"],
example: "/esquirehk/tag/Fashion",
parameters: { id: "标签,可在对应标签页 URL 中找到" },
name: "Tag",
maintainers: ["nczitzk"],
radar: [{ source: ["www.esquirehk.com/tag/:id", "www.esquirehk.com/:id"] }],
handler
};
//#endregion
export { route };