From 20c7a781465a360d9044619643c9757fa1d27282 Mon Sep 17 00:00:00 2001 From: chenxiangcheng_work Date: Fri, 26 Jul 2024 12:24:47 +0800 Subject: [PATCH] style(route/cffex): modify code style --- lib/routes/cffex/announcement.ts | 39 +++++++++++++------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/lib/routes/cffex/announcement.ts b/lib/routes/cffex/announcement.ts index b7ce5272546fd2..f9d449335ed79b 100644 --- a/lib/routes/cffex/announcement.ts +++ b/lib/routes/cffex/announcement.ts @@ -7,12 +7,12 @@ import cache from '@/utils/cache'; export const route: Route = { path: '/announcement', - name: '中国金融期货交易所 - 交易所公告', + name: '交易所公告', url: 'www.cffex.com.cn', maintainers: ['ChenXiangcheng1'], example: '/cffex/announcement', parameters: {}, - description: `欢迎订阅!!! 我维护的 cffex 交易所公告!!! `, + description: '', categories: ['government'], features: { requireConfig: false, @@ -25,7 +25,7 @@ export const route: Route = { radar: [ { source: ['cffex.com.cn'], - target: '/cffex/announcement', + target: '/announcement', }, ], handler, @@ -34,9 +34,7 @@ export const route: Route = { async function handler(): Promise<{ title: string; link: string; item: DataItem[] }> { const baseUrl = 'http://www.cffex.com.cn'; const homeUrl = `${baseUrl}/jystz`; - const response = await ofetch(homeUrl, { - headers: {}, - }); + const response = await ofetch(homeUrl); // 使用 Cheerio 选择器解析 HTML const $ = load(response); @@ -44,13 +42,13 @@ async function handler(): Promise<{ title: string; link: string; item: DataItem[ .toArray() .map((item) => { item = $(item); // (Element) -> LoadedCheerio - const a1 = $(item).find('a').first(); - const a2 = $(item).find('a').eq(1); + const titleEle = $(item).find('a').first(); + const dateEle = $(item).find('a').eq(1); return { - title: a1.text().trim(), - link: `${baseUrl}${a1.attr('href')}`, - pubDate: timezone(parseDate(a2.text(), 'YYYY-MM-DD'), +8), + title: titleEle.text().trim(), + link: `${baseUrl}${titleEle.attr('href')}`, + pubDate: timezone(parseDate(dateEle.text(), 'YYYY-MM-DD'), +8), }; }); @@ -58,22 +56,17 @@ async function handler(): Promise<{ title: string; link: string; item: DataItem[ const items = await Promise.all( // (Promise|null) -> Promise|null list.map((item) => - cache.tryGet( - item.link, - async () => { - const response = await ofetch(item.link); - const $ = load(response); - item.description = $('div.jysggnr div.nan p').eq(1)?.html(); - return item; - }, - 3600, - true - ) + cache.tryGet(item.link, async () => { + const response = await ofetch(item.link); + const $ = load(response); + item.description = $('div.jysggnr div.nan p').eq(1)?.html(); + return item; + }) ) ); return { - title: `中国金融期货交易所 - 交易所公告`, + title: '中国金融期货交易所 - 交易所公告', link: homeUrl, item: items, };