rsshub
Version:
Make RSS Great Again!
139 lines (137 loc) • 4.41 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import { t as ViewType } from "./types-D84BRIt4.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 { load } from "cheerio";
//#region lib/routes/ltaaa/article.ts
init_esm_shims();
const handler = async (ctx) => {
const limit = Number.parseInt(ctx.req.query("limit") ?? "30", 10);
const baseUrl = "https://www.ltaaa.cn";
const targetUrl = new URL("article", baseUrl).href;
const $ = load(await ofetch_default(targetUrl));
const language = $("html").attr("lang") ?? "zh-CN";
let items = [];
items = $("ul.wlist li").slice(0, limit).toArray().map((el) => {
const $el = $(el);
const $aEl = $el.find("div.li-title a");
const title$1 = $aEl.text();
const description = art(path.join(__dirname, "templates/description-ca64252b.art"), { intro: $el.find("div.dbody p").first().text() });
const pubDateStr = $el.find("i.icon-time").next().text().trim();
const linkUrl = $aEl.attr("href");
const authors = $el.find("i.icon-user").parent().find("a").toArray().map((authorEl) => {
const $authorEl = $(authorEl);
return {
name: $authorEl.text(),
url: new URL($authorEl.attr("href") ?? "", baseUrl).href,
avatar: void 0
};
});
const image = $el.find("div.li-thumb img").attr("src");
const upDatedStr = pubDateStr;
return {
title: title$1,
description,
pubDate: pubDateStr ? parseDate(pubDateStr) : void 0,
link: linkUrl ? new URL(linkUrl, baseUrl).href : void 0,
author: authors,
content: {
html: description,
text: description
},
image,
banner: image,
updated: upDatedStr ? parseDate(upDatedStr) : void 0,
language
};
});
items = (await Promise.all(items.map((item) => {
if (!item.link) return item;
return cache_default.tryGet(item.link, async () => {
const $$ = load(await ofetch_default(item.link));
const title$1 = $$("div.post-title").text();
const pubDateStr = $$("i.icon-time").next().text().trim();
const categoryEls = $$("span.keywords a").toArray();
const categories = [...new Set(categoryEls.map((el) => $$(el).text()).filter(Boolean))];
const authors = $$("i.icon-user").first().nextAll("a").toArray().map((authorEl) => {
const $$authorEl = $$(authorEl);
return {
name: $$authorEl.text(),
url: new URL($$authorEl.attr("href") ?? "", baseUrl).href,
avatar: void 0
};
});
const upDatedStr = pubDateStr;
$$("div.post-tip").each((_, el) => {
const $$el = $$(el);
const content = $$el.html() ?? "";
if (content) $$el.replaceWith(`<h1>${content}</h1>`);
});
$$("div.post-param, div.post-title, div.post-keywords").remove();
$$("div.attitude, div.clear").remove();
const description = art(path.join(__dirname, "templates/description-ca64252b.art"), { description: $$("div.post-body").html() });
const processedItem = {
title: title$1,
description,
pubDate: pubDateStr ? parseDate(pubDateStr) : item.pubDate,
category: categories,
author: authors,
content: {
html: description,
text: description
},
updated: upDatedStr ? parseDate(upDatedStr) : item.updated,
language
};
return {
...item,
...processedItem
};
});
}))).filter((_) => true);
const title = $("title").text();
return {
title,
description: $("meta[name=\"description\"]").attr("content"),
link: targetUrl,
item: items,
allowEmpty: true,
image: new URL("static/home/images/logo.png", baseUrl).href,
author: title.split(/-/).pop(),
language,
id: targetUrl
};
};
const route = {
path: "/article",
name: "网站翻译",
url: "www.ltaaa.cn",
maintainers: ["nczitzk"],
handler,
example: "/ltaaa/article",
parameters: void 0,
description: void 0,
categories: ["new-media"],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["www.ltaaa.cn/article"],
target: "/article"
}],
view: ViewType.Articles
};
//#endregion
export { handler, route };