rsshub
Version:
Make RSS Great Again!
79 lines (76 loc) • 2.21 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/digitaling/article.ts
const categoryTitle = /* @__PURE__ */ new Map([
["latest", {
name: "最新文章",
type: {}
}],
["headline", {
name: "头条",
type: {}
}],
["hot", {
name: "热文",
type: {
views: "近期热门文章",
collects: "近期最多收藏",
zan: "近期最多赞"
}
}],
["choice", {
name: "精选",
type: {}
}]
]);
const route = {
path: "/articles/:category/:subcate?",
categories: ["new-media"],
example: "/digitaling/articles/latest",
parameters: {
category: "文章专题分类",
subcate: "hot 分类下的子类"
},
name: "数英网文章专题",
maintainers: ["occupy5"],
description: `| 最新文章 | 头条 | 热文 | 精选 |
| -------- | -------- | ---- | ------ |
| latest | headline | hot | choice |
分类\`hot\`下的子类
| 近期热门文章 | 近期最多收藏 | 近期最多赞 |
| ------------ | ------------ | ---------- |
| views | collects | zan |`,
handler
};
async function handler(ctx) {
let category = ctx.req.param("category") || "latest";
const subcate = ctx.req.param("subcate");
let title = categoryTitle.get(category).name;
if (category === "latest") category = "";
let link = `https://www.digitaling.com/articles/${category}/`;
if (subcate) {
link += subcate;
title += "/" + categoryTitle.get(category).type[subcate];
}
const $ = load(await rofetch(link));
const list = $(".con_list li h3").find("a").toArray().map((e) => $(e).attr("href"));
const out = await Promise.all(list.map((itemUrl) => cache_default.tryGet(itemUrl, async () => {
const $ = load(await rofetch(itemUrl));
return {
title: $(".article_title h1").text(),
author: $("#avatar_by").parent().find("h3 a").text(),
link: itemUrl,
description: $("#article_con").html(),
pubDate: parseDate($("#edit_url").parent().children().last().text())
};
})));
return {
title: `数英网-文章专题-${title}`,
link,
item: out
};
}
//#endregion
export { route };