From 4492c051bea0971f8a316e533a5e6029b2b82a2e Mon Sep 17 00:00:00 2001 From: Millium Orion <664834952@qq.com> Date: Tue, 22 Jul 2025 18:11:04 +0800 Subject: [PATCH] feat(route): add TechCrunch category route (#19665) --- lib/routes/techcrunch/category.ts | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 lib/routes/techcrunch/category.ts diff --git a/lib/routes/techcrunch/category.ts b/lib/routes/techcrunch/category.ts new file mode 100644 index 000000000..ddb52ddb6 --- /dev/null +++ b/lib/routes/techcrunch/category.ts @@ -0,0 +1,48 @@ +import { Route } from '@/types'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; +import path from 'node:path'; + +const host = 'https://techcrunch.com'; +export const route: Route = { + path: '/category/:categoryId', + categories: ['new-media'], + example: '/techcrunch/category/577047203', + parameters: { + categoryId: '分类id', + }, + name: 'Category', + maintainers: ['MilliumOrion'], + handler, + description: `Use the category ID to retrieve a list of articles, category ID. +From the page source of \`https://techcrunch.com/category/***\`, locate the \`{category_id}\` +Example: +\`html\` -> \`head\` -> \`\``, +}; + +async function handler(ctx) { + const categoryId = ctx.req.param('categoryId'); + const { data } = await got(`${host}/wp-json/wp/v2/posts?categories=${categoryId}`); + const items = data.map((item) => { + const head = item.yoast_head_json; + const $ = load(item.content.rendered, null, false); + return { + title: item.title.rendered, + description: art(path.join(__dirname, 'templates/description.art'), { + head, + rendered: $.html(), + }), + link: item.link, + pubDate: parseDate(item.date_gmt), + }; + }); + + return { + title: 'TechCrunch', + link: host, + description: 'Reporting on the business of technology, startups, venture capital funding, and Silicon Valley.', + item: items, + }; +}