rsshub
Version:
Make RSS Great Again!
125 lines (123 loc) • 3.48 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import { t as ViewType } from "./types-D84BRIt4.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import path from "node:path";
import { load } from "cheerio";
import markdownit from "markdown-it";
//#region lib/routes/dgtle/feed.ts
init_esm_shims();
const md = markdownit({
html: true,
linkify: true
});
const handler = async (ctx) => {
const limit = Number.parseInt(ctx.req.query("limit") ?? "30", 10);
const baseUrl = "https://www.dgtle.com";
const targetUrl = new URL("feed", baseUrl).href;
const apiUrl = new URL("feed/getHotDynamic", baseUrl).href;
const response = await ofetch_default(apiUrl, { query: { last_id: 0 } });
const $ = load(await ofetch_default(targetUrl));
const language = $("html").attr("lang") ?? "zh-CN";
let items = [];
items = response.data.dataList.slice(0, limit).map((item) => {
const content = item.content ? md.render(item.content) : "";
const title = $(content).text();
const description = art(path.join(__dirname, "templates/description-36fefaf3.art"), {
images: item.imgs_url.map((src) => ({ src })),
description: content
});
const pubDate = item.created_at;
const linkUrl = item.url;
const categories = [...new Set((item.tags_info?.map((t) => t.title) ?? []).filter(Boolean))];
const authors = [{
name: item.user_name,
url: new URL(`user?uid=${item.encode_uid}`, baseUrl).href,
avatar: item.avatar_path
}];
const guid = `dgtle-${item.id}`;
const image = item.imgs_url?.[0];
const updated = item.updated_at ?? pubDate;
let processedItem = {
title,
description,
pubDate: pubDate ? parseDate(pubDate, "X") : void 0,
link: linkUrl ? new URL(linkUrl, baseUrl).href : void 0,
category: categories,
author: authors,
guid,
id: guid,
content: {
html: description,
text: description
},
image,
banner: image,
updated: updated ? parseDate(updated, "X") : void 0,
language
};
const medias = (() => {
const acc = {};
for (const media of item.imgs_url) {
const url = media;
if (!url) continue;
const medium = "image";
const key = `${medium}${Object.values(acc).filter((m) => m.medium === medium).length + 1}`;
acc[key] = {
url,
medium,
title: "",
description: "",
thumbnail: url
};
}
return acc;
})();
processedItem = {
...processedItem,
media: medias
};
return processedItem;
});
return {
title: $("title").text(),
description: $("meta[name=\"description\"]").attr("content"),
link: targetUrl,
item: items,
allowEmpty: true,
author: $("meta[name=\"keywords\"]").attr("content")?.split(/,/)[0] ?? void 0,
language,
id: targetUrl
};
};
const route = {
path: "/feed",
name: "兴趣",
url: "www.dgtle.com",
maintainers: ["nczitzk"],
handler,
example: "/dgtle/feed",
parameters: void 0,
description: void 0,
categories: ["new-media"],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["www.dgtle.com/feed"],
target: "/feed"
}],
view: ViewType.Articles
};
//#endregion
export { handler, route };