rsshub
Version:
Make RSS Great Again!
63 lines (61 loc) • 1.93 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 "./helpers-DxBp0Pty.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { load } from "cheerio";
//#region lib/routes/luogu/daily.ts
const route = {
path: "/daily/:id?",
categories: ["programming"],
example: "/luogu/daily",
parameters: { id: "年度日报所在帖子 id,可在 URL 中找到,不填默认为 `47327`" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["luogu.com.cn/discuss/47327", "luogu.com.cn/"],
target: "/daily"
}],
name: "日报",
maintainers: [
"LogicJake",
"prnake",
"nczitzk"
],
handler,
url: "luogu.com.cn/discuss/47327"
};
async function handler(ctx) {
const link = `https://www.luogu.com.cn/discuss/${ctx.req.param("id") ?? 47327}`;
const $ = load((await got_default(link)).data);
const title = $("head title").text();
const jsonRaw = $("head script:contains(\"window._feInjection\")").text().match(/window\._feInjection = JSON\.parse\(decodeURIComponent\("(.*?)"\)\);/)[1];
const jsonDecode = JSON.parse(decodeURIComponent(jsonRaw));
const dailyLink = jsonDecode.currentData.post.content.match(/<([^>]*)>/)[1];
const { data: dailyResponse } = await got_default(dailyLink);
const $daily = load(dailyResponse);
const issueHeading = $daily(".am-article-title").first().text().trim();
return {
title: "洛谷日报",
link,
item: [{
title,
description: $daily("#article-content").html(),
link,
author: jsonDecode.currentData.post.author.name,
guid: `${link}#${issueHeading}`,
pubDate: parseDate(jsonDecode.currentData.post.time)
}]
};
}
//#endregion
export { route };