rsshub
Version:
Make RSS Great Again!
54 lines (52 loc) • 1.5 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { load } from "cheerio";
//#region lib/routes/yidoutang/case.ts
const route = {
path: "/case/:type",
categories: ["new-media"],
example: "/yidoutang/case/hot",
parameters: { type: "类型, 默认为`default`" },
name: "全屋记",
maintainers: ["sanmmm"],
handler,
description: `类型
| 默认 | 最热 | 最新 |
| ------- | ---- | ---- |
| default | hot | new |`
};
const urlPathMap = {
default: "",
hot: "/0-2-0-0-0-0/",
new: "/0-1-0-0-0-0/"
};
const typeLabelMap = {
default: "默认",
hot: "热门",
new: "最新"
};
async function handler(ctx) {
const { type = "default" } = ctx.req.param();
const url = `http://www.yidoutang.com/case${urlPathMap[type]}`;
const $ = load(await rofetch(url));
const items = $(".main .case-items > .case-item").toArray().map((ele) => {
const $item = $(ele);
const baseInfoNode = $item.find(".info > .text");
const desc = baseInfoNode.find(".desc").text();
const thumbnail = $item.find(".img-box img").attr("src");
return {
title: baseInfoNode.find(".title").text(),
link: baseInfoNode.find("a").attr("href"),
description: [`简介: ${desc}`, `<img src="${thumbnail}"/>`].join("<br/>"),
author: $item.find(".user a").text()
};
});
const typeLabel = typeLabelMap[type];
return {
title: `一兜糖 - 全屋记 - ${typeLabel}`,
description: `一兜糖 - 全屋记 - ${typeLabel}`,
link: url,
item: items
};
}
//#endregion
export { route };