rsshub
Version:
Make RSS Great Again!
49 lines (48 loc) • 1.81 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { load } from "cheerio";
//#region lib/routes/cell/cell.ts
const route = {
path: "/cell/:category",
categories: ["journal"],
example: "/cell/cell/current",
parameters: { category: "Query type, see the table below" },
features: { supportScihub: true },
name: "Current Issue",
maintainers: ["y9c"],
description: `| \`:category\` | Query Type |
| :---------: | :---------------------: |
| current | Current Issue (default) |
| inpress | Articles in press |`,
handler
};
async function handler(ctx) {
const baseURL = "https://www.cell.com";
const { category } = ctx.req.param();
const inPress = category === "inpress";
const pageURL = inPress ? `${baseURL}/cell/inpress.rss` : `${baseURL}/cell/current.rss`;
const categoryTitle = inPress ? "Articles in press" : "Latest issue";
const $ = load(await rofetch(pageURL, { responseType: "text" }), { xmlMode: true });
const out = $("item").toArray().map((item) => {
const $item = $(item);
const section = $item.find(String.raw`prism\:section`).text();
const address = $item.find("link").text().replace("?rss=yes", "");
return {
title: $item.find(String.raw`dc\:title`).text(),
author: $item.find(String.raw`dc\:creator`).text(),
description: `<p style="color: #007dbc; text-transform: uppercase; font-weight: 700;">${section}</p>${$item.find("description").text()}`,
link: address,
guid: address,
doi: $item.find(String.raw`dc\:identifier`).text(),
pubDate: parseDate($item.find(String.raw`dc\:date`).text())
};
});
return {
title: `Cell | ${categoryTitle}`,
description: "Cell, a research journal",
link: baseURL,
item: out
};
}
//#endregion
export { route };