rsshub
Version:
Make RSS Great Again!
110 lines (108 loc) • 3.63 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./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 art } from "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/kadokawa/blog.ts
init_esm_shims();
const handler = async (ctx) => {
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 10;
const rootUrl = "https://www.kadokawa.com.tw";
const currentUrl = new URL("blog/posts", rootUrl).href;
const { data: response } = await got_default(currentUrl);
const $ = load(response);
const language = $("html").prop("lang");
let items = $("div.List-item").slice(0, limit).toArray().map((item) => {
item = $(item);
const image$1 = item.find("div.List-item-excerpt img").prop("src")?.split(/\?/)[0] ?? void 0;
const title = item.find("h2.List-item-title").text();
const description = art(path.join(__dirname, "templates/description-881baa33.art"), {
images: image$1 ? [{
src: image$1,
alt: title
}] : void 0,
intro: item.find("div.List-item-preview").text()
});
return {
title,
description,
pubDate: parseDate(item.find("span.primary-border-color-after").text()),
link: new URL(item.find("a").prop("href"), rootUrl).href,
content: {
html: description,
text: item.find("div.List-item-preview").text()
},
image: image$1,
banner: image$1,
language,
enclosure_url: image$1,
enclosure_type: image$1 ? `image/${image$1.split(/\./).pop()}` : void 0,
enclosure_title: title
};
});
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
const { data: detailResponse } = await got_default(item.link);
const $$ = load(detailResponse);
const title = $$("h1.Post-title").text().trim();
const description = art(path.join(__dirname, "templates/description-881baa33.art"), { description: $$("div.Post-content").html() });
const image$1 = $$("meta[property=\"og:image\"]").prop("content")?.split(/\?/)[0] ?? void 0;
item.title = title;
item.description = description;
item.pubDate = parseDate($$("div.Post-date").text().trim());
item.content = {
html: description,
text: $$("div.Post-content").text()
};
item.image = image$1;
item.banner = image$1;
item.language = language;
item.enclosure_url = image$1;
item.enclosure_type = image$1 ? `image/${image$1.split(/\./).pop()}` : void 0;
item.enclosure_title = title;
return item;
})));
const image = new URL($("meta[property=\"og:image\"]").prop("content"), rootUrl).href;
return {
title: $("title").text(),
description: $("meta[property=\"og:description\"]").prop("content"),
link: currentUrl,
item: items,
allowEmpty: true,
image,
author: $("meta[property=\"og:site_name\"]").prop("content"),
language
};
};
const route = {
path: "/blog",
name: "角編新聞台",
url: "kadokawa.com.tw",
maintainers: ["nczitzk"],
handler,
example: "/kadokawa/blog",
parameters: void 0,
description: "",
categories: ["blog"],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["kadokawa.com.tw/blog/posts"],
target: "/blog"
}]
};
//#endregion
export { handler, route };