rsshub
Version:
Make RSS Great Again!
71 lines (69 loc) • 2.21 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
//#region lib/routes/sspai/tag.ts
const route = {
path: "/tag/:keyword",
categories: ["new-media"],
example: "/sspai/tag/apple",
parameters: { keyword: "关键词" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{ source: ["sspai.com/tag/:keyword"] }],
name: "标签订阅",
maintainers: ["Jeason0228"],
handler
};
async function handler(ctx) {
const keyword = ctx.req.param("keyword");
const keyword_encode = encodeURIComponent(decodeURIComponent(keyword));
const api_url = `https://sspai.com/api/v1/articles?offset=0&limit=50&has_tag=1&tag=${keyword_encode}&include_total=false`;
const host = `https://beta.sspai.com/tag/${keyword_encode}`;
const data = (await got_default({
method: "get",
url: api_url,
headers: { Referer: host }
})).data.list;
const items = await Promise.all(data.map((item) => {
const link = `https://sspai.com/api/v1/article/info/get?id=${item.id}&view=second&support_webp=true`;
let description;
const key = `sspai: ${item.id}`;
return cache_default.tryGet(key, async () => {
const articleData = (await got_default({
method: "get",
url: link,
headers: { Referer: host }
})).data.data;
const banner = articleData.promote_image;
if (banner) description = `<img src="${banner}" alt="Article Cover Image" style="display: block; margin: 0 auto;"><br>`;
description += articleData.body;
return {
title: item.title.trim(),
description,
link: `https://sspai.com/post/${item.id}`,
pubDate: parseDate(item.released_at * 1e3),
author: item.author.nickname
};
});
}));
return {
title: `#${keyword} - 少数派`,
link: host,
description: `${keyword} 更新推送 `,
item: items
};
}
//#endregion
export { route };