From e5d191c362959950f47891ed87f8fae9f41b29b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8B=E9=9B=A8=E5=B0=B1=E5=83=8F=E5=BC=B9=E9=92=A2?= =?UTF-8?q?=E7=90=B4=F0=9F=8E=B9?= Date: Thu, 25 Jul 2024 19:19:07 +0800 Subject: [PATCH] feat(route): add v2ex xna (#16251) * feat(route): add v2ex xna * Update lib/routes/v2ex/xna.ts feat: v2ex xna limit default set to 50 --------- --- lib/routes/v2ex/xna.ts | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 lib/routes/v2ex/xna.ts diff --git a/lib/routes/v2ex/xna.ts b/lib/routes/v2ex/xna.ts new file mode 100644 index 000000000..6dcf2eff8 --- /dev/null +++ b/lib/routes/v2ex/xna.ts @@ -0,0 +1,55 @@ +import { Route, ViewType } from '@/types'; +import got from '@/utils/got'; +import { load } from 'cheerio'; + +export const route: Route = { + path: '/xna', + categories: ['bbs', 'blog'], + view: ViewType.Articles, + example: '/v2ex/xna', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: 'XNA', + maintainers: ['luckyscript'], + handler, +}; + +async function handler(ctx) { + const host = 'https://v2ex.com'; + const pageUrl = `${host}/xna`; + + const response = await got({ + method: 'get', + url: pageUrl, + }); + + const $ = load(response.data); + const items = $('div.xna-entry-main-container') + .toArray() + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 50) + .map((dom) => { + const link = $(dom).find('.xna-entry-title > a'); + const author = $(dom).find('.xna-source-author > a').text(); + + return { + title: $(link).text(), + link: $(link).attr('href'), + description: $(link).text(), + author, + }; + }); + + return { + title: `V2EX-xna`, + link: pageUrl, + description: `V2EX-xna`, + item: items, + }; +}