From 7ac4ffd1ae28753fa2b7f7a77564152da7a0c52f Mon Sep 17 00:00:00 2001 From: Jia Chen Date: Mon, 25 Mar 2024 00:27:11 +0800 Subject: [PATCH] feat(route): recover route blogread/newest (#14937) * feat(route): recover route blogread/newest * fix(route): Update lib/routes/blogread/index.ts * Update lib/routes/blogread/index.ts --------- --- lib/router.js | 3 -- .../newest.js => routes/blogread/index.ts} | 29 ++++++++++++++----- lib/routes/blogread/namespace.ts | 6 ++++ 3 files changed, 28 insertions(+), 10 deletions(-) rename lib/{routes-deprecated/blogread/newest.js => routes/blogread/index.ts} (52%) create mode 100644 lib/routes/blogread/namespace.ts diff --git a/lib/router.js b/lib/router.js index 6acc307b7af260..215bd0e567cf10 100644 --- a/lib/router.js +++ b/lib/router.js @@ -379,9 +379,6 @@ router.get('/geekpark/breakingnews', lazyloadRouteHandler('./routes/geekpark/bre // 香港天文台 router.get('/hko/weather', lazyloadRouteHandler('./routes/hko/weather')); -// 技术头条 -router.get('/blogread/newest', lazyloadRouteHandler('./routes/blogread/newest')); - // gnn游戏新闻 router.get('/gnn/gnn', lazyloadRouteHandler('./routes/gnn/gnn')); diff --git a/lib/routes-deprecated/blogread/newest.js b/lib/routes/blogread/index.ts similarity index 52% rename from lib/routes-deprecated/blogread/newest.js rename to lib/routes/blogread/index.ts index 8e1872b2cc340f..bef75385ca37c3 100644 --- a/lib/routes-deprecated/blogread/newest.js +++ b/lib/routes/blogread/index.ts @@ -1,8 +1,23 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import { Route } from '@/types'; +import got from '@/utils/got'; +import * as cheerio from 'cheerio'; -module.exports = async (ctx) => { - const url = 'http://blogread.cn/news/newest.php'; +export const route: Route = { + path: '/newest', + categories: ['programming'], + example: '/blogread/newest', + radar: [ + { + source: ['blogread.cn/news/newest.php'], + }, + ], + name: '最新文章', + maintainers: ['fashioncj'], + handler, +}; + +async function handler() { + const url = 'https://blogread.cn/news/newest.php'; const response = await got({ method: 'get', url, @@ -12,19 +27,19 @@ module.exports = async (ctx) => { .map((index, elem) => { elem = $(elem); const $link = elem.find('dt a'); - return { title: $link.text(), description: elem.find('dd').eq(0).text(), link: $link.attr('href'), author: elem.find('.small a').eq(0).text(), + pubDate: elem.find('dd').eq(1).text().split('\n')[2], }; }) .get(); - ctx.state.data = { + return { title: '技术头条', link: url, item: resultItem, }; -}; +} diff --git a/lib/routes/blogread/namespace.ts b/lib/routes/blogread/namespace.ts new file mode 100644 index 00000000000000..7f56723d3350ae --- /dev/null +++ b/lib/routes/blogread/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '技术头条', + url: 'blogread.cn', +};