rsshub
Version:
Make RSS Great Again!
66 lines (64 loc) • 2.31 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import { n as gqlEndpoint, r as parseItem, t as baseUrl } from "./utils-Dik9yXN-.mjs";
import * as cheerio from "cheerio";
//#region lib/routes/matters/tags.ts
const getTagId = (tid) => cache_default.tryGet(`matters:tags:${tid}`, async () => {
const response = await ofetch_default(`${baseUrl}/tags/${tid}`);
const $ = cheerio.load(response);
const nextData = JSON.parse($("script#__NEXT_DATA__").text());
return (Object.entries(nextData.props.apolloState.data.ROOT_QUERY).find(([key]) => key.startsWith("node"))?.pop())?.id.split(":")[1];
});
const handler = async (ctx) => {
const { tid } = ctx.req.param();
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 20;
const node = (await ofetch_default(gqlEndpoint, {
method: "POST",
body: { query: `{
node(input: {id: "${await getTagId(tid)}"}) {
... on Tag {
content
description
articles(input: {first: ${limit}}) {
edges {
node {
title
shortHash
content
createdAt
author {
displayName
}
tags {
content
}
}
}
}
}
}
}` }
})).data.node;
return {
title: `Matters | ${node.content}`,
link: `${baseUrl}/tags/${tid}`,
description: node.description,
item: node.articles.edges.map(({ node: node$1 }) => parseItem(node$1))
};
};
const route = {
path: "/tags/:tid",
name: "Tags",
example: "/matters/tags/972-哲學",
parameters: { tid: "Tag id, can be found in the url of the tag page" },
maintainers: ["Cerebrater"],
handler,
radar: [{ source: ["matters.town/tags/:tid"] }]
};
//#endregion
export { route };