rsshub
Version:
Make RSS Great Again!
58 lines (57 loc) • 2.63 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";
import { decodeXML } from "entities";
//#region lib/routes/aozora/newbook.ts
const route = {
path: "/newbook/:count?",
categories: ["reading"],
example: "/aozora/newbook/10",
parameters: { count: "更新数量. 设置每次下载列表大小. 范围是 1 到 50." },
description: "书籍网站每日一更。信息更新时间为书籍最初出版时间,排序可能不符合网络发表时间,请认准未读消息.",
name: "新着リスト",
maintainers: ["sgqy"],
handler
};
const baseUrl = "https://www.aozora.gr.jp/index_pages/";
async function handler(ctx) {
const listUrl = `${baseUrl}whatsnew1.html`;
const $ = load(await rofetch(listUrl));
const list = $("table.list tr");
let count = Number.parseInt(ctx.req.param("count") ?? "");
if (Number.isNaN(count) || count < 1) count = 10;
else if (count > 50) count = 50;
const detailUrls = [];
for (let i = 1; i < count + 1; ++i) detailUrls.push(baseUrl + $(list[i]).find("a").attr("href"));
return {
title: "青空文庫新着リスト",
link: listUrl,
item: await Promise.all(detailUrls.map((detailUrl) => cache_default.tryGet(detailUrl, async () => {
const $detail = load(await rofetch(detailUrl));
const link = $detail("meta[property=\"og:url\"]").attr("content");
let author = "";
let title = "";
let titleSub = "";
for (const element of $detail("table[summary=\"タイトルデータ\"] > tbody > tr").toArray()) {
const tmp = decodeXML($detail(element).html());
if (tmp.includes("作品名:")) title = $detail(element).find("td:nth-child(2)").text();
if (tmp.includes("副題:")) titleSub = $detail(element).find("td:nth-child(2)").text();
if (tmp.includes("著者名:")) author = $detail(element).find("td:nth-child(2)").text();
}
if (titleSub !== "") title += " —— " + titleSub;
const pubDateNum = $detail("table[summary=\"底本データ\"] > tbody > tr:nth-child(3) > td:nth-child(2)").text().replaceAll(/(.*)|日/g, "").replaceAll(/[年月]/g, "-");
const fullTextLinkHtml = `<a href="${$detail("table.download > tbody > tr:nth-child(3) > td:nth-child(3) > a").attr("href")}">いますぐXHTML版で読む</a><br>`;
const summury = $detail("table[summary=\"作品データ\"]").html();
return {
title,
author,
pubDate: parseDate(pubDateNum),
link,
description: fullTextLinkHtml + summury
};
})))
};
}
//#endregion
export { route };