From cee538dc756d282e45e1cbf14c400138ce4264ac Mon Sep 17 00:00:00 2001 From: CanonNi Date: Tue, 18 Mar 2025 15:35:39 +0800 Subject: [PATCH] feat(route): add cherrytimes (#18609) * feat(route): add cherrytimes * fix lint errors * optimize * more lint errors * fetch first page only --- lib/routes/cherrytimes/market.ts | 33 +++++++++++++++++++++++++++++ lib/routes/cherrytimes/namespace.ts | 6 ++++++ 2 files changed, 39 insertions(+) create mode 100644 lib/routes/cherrytimes/market.ts create mode 100644 lib/routes/cherrytimes/namespace.ts diff --git a/lib/routes/cherrytimes/market.ts b/lib/routes/cherrytimes/market.ts new file mode 100644 index 000000000..5759ef64a --- /dev/null +++ b/lib/routes/cherrytimes/market.ts @@ -0,0 +1,33 @@ +import { Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { load } from 'cheerio'; + +export const route: Route = { + path: '/market', + categories: ['new-media'], + example: '/cherrytimes/market', + name: 'Market', + maintainers: ['canonnizq'], + + handler: async () => { + const response = await ofetch("https://cherrytimes.it/en/tag/markets?page=1"); + const $ = load(response); + const items = $('div.post-container').toArray().map((item) => { + const element = $(item); + const a = element.find('a').eq(1); + + return { + title: a.text(), + link: a.attr('href'), + description: element.find('p.excerpt').text(), + category: element.find('a').last().text(), + }; + }); + + return { + title: 'Cherry Times - Market', + link: 'https://cherrytimes.it/en/tag/markets', + item: items, + }; + }, +}; diff --git a/lib/routes/cherrytimes/namespace.ts b/lib/routes/cherrytimes/namespace.ts new file mode 100644 index 000000000..0550a1245 --- /dev/null +++ b/lib/routes/cherrytimes/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Cherry Times', + url: 'cherrytimes.it', +}; \ No newline at end of file