rsshub
Version:
Make RSS Great Again!
53 lines (52 loc) • 1.52 kB
JavaScript
import { t as fetchPage } from "./utils-BfVfihln.mjs";
import { load } from "cheerio";
//#region lib/routes/xiachufang/user.ts
const route = {
path: "/user/:id/:type?",
categories: ["study"],
example: "/xiachufang/user/103309404",
parameters: {
id: "用户 id, 可在用户主页 URL 中找到",
type: {
description: "类型",
options: [{
value: "created",
label: "菜谱"
}, {
value: "cooked",
label: "作品"
}],
default: "created"
}
},
name: "用户菜谱/作品",
maintainers: ["xyqfer"],
handler
};
async function handler(ctx) {
const { id, type = "created" } = ctx.req.param();
const url = `https://www.xiachufang.com/cook/${id}/`;
const $ = load(await fetchPage(url));
const author = $(".page-title").text().trim();
const items = $(`${type === "cooked" ? ".dishes-280-full-width-list" : ".recipes-280-full-width-list"} li`).toArray().map((item) => {
const $item = $(item);
const $link = $item.find(".name a");
const title = $link.text();
const img = $item.find(".cover img").attr("data-src").replace(/\?.+/, "");
const desc = $item.find(".desc").text().trim() || $item.find(".stats").text().trim();
return {
title,
link: `https://www.xiachufang.com${$link.attr("href")}`,
description: `<img src="${img}"><br>${desc}`
};
});
return {
title: `下厨房-${author}`,
description: $(".people-base-desc").text().trim(),
link: url,
image: $(".people-base-left.avatar img").attr("src"),
item: items
};
}
//#endregion
export { route };