From b8b2065e57c4c7c0b2b2c8a1236378576f19d3f8 Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 9 Apr 2026 09:00:10 +0800 Subject: [PATCH] feat(route): add trendforce (#21665) * feat(route): add trendforce * fix: pubDate --- lib/routes/trendforce/namespace.ts | 4 ++ lib/routes/trendforce/news-cn.ts | 77 ++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 lib/routes/trendforce/news-cn.ts diff --git a/lib/routes/trendforce/namespace.ts b/lib/routes/trendforce/namespace.ts index b52d0094a..78b1bf429 100644 --- a/lib/routes/trendforce/namespace.ts +++ b/lib/routes/trendforce/namespace.ts @@ -6,4 +6,8 @@ export const namespace: Namespace = { categories: ['new-media'], description: '', lang: 'en', + zh: { + name: '集邦咨询', + url: 'trendforce.cn', + }, }; diff --git a/lib/routes/trendforce/news-cn.ts b/lib/routes/trendforce/news-cn.ts new file mode 100644 index 000000000..b10979cea --- /dev/null +++ b/lib/routes/trendforce/news-cn.ts @@ -0,0 +1,77 @@ +import { load } from 'cheerio'; + +import type { Route } from '@/types'; +import cache from '@/utils/cache'; +import ofetch from '@/utils/ofetch'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/cn/presscenter/news', + categories: ['new-media'], + example: '/trendforce/cn/presscenter/news', + radar: [ + { + source: ['www.trendforce.cn/presscenter/news'], + }, + ], + name: '产业洞察', + maintainers: ['TonyRL'], + handler, + url: 'www.trendforce.cn/presscenter/news', +}; + +async function handler() { + const baseUrl = 'https://www.trendforce.cn'; + const link = `${baseUrl}/presscenter/news`; + + const response = await ofetch(link); + const $ = load(response); + + const list = $('.list-items .list-item') + .toArray() + .map((item) => { + const $item = $(item); + const a = $item.find('h3 a.title-link'); + return { + title: a.find('strong').text().trim(), + link: new URL(a.attr('href')!, baseUrl).href, + description: $item.find('p').text()?.trim(), + pubDate: parseDate($item.find('h4').text().trim()), + }; + }); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const response = await ofetch(item.link); + const $ = load(response); + + const pressCenter = $('.presscenter'); + const tagRow = pressCenter.find('.tag-row'); + + item.category = tagRow + .find('.fa-bookmark') + .parent() + .find('a') + .toArray() + .map((a) => $(a).text().trim()); + item.author = tagRow.find('.fa-user').parent().find('a').text().trim(); + + pressCenter.find('h1, .tag-row, .press-choose-post, hr').remove(); + + item.description = pressCenter.html()?.trim(); + + return item; + }) + ) + ); + + return { + title: $('head title').text().trim(), + description: $('meta[name="description"]').attr('content'), + link, + language: $('html').attr('lang'), + image: `${baseUrl}${$('link[rel="apple-touch-icon-precomposed"][sizes="152x152"]').attr('href')}`, + item: items, + }; +}