From b55cb252872b1ad718d9de661986d3f5bdb0d413 Mon Sep 17 00:00:00 2001 From: Andvari <31068367+dzx-dzx@users.noreply.github.com> Date: Sat, 27 Apr 2024 20:18:29 +0800 Subject: [PATCH 1/2] fix(route/sjtu/yzb): Correct title and date. (#15387) --- lib/routes/sjtu/yzb/zkxx.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/routes/sjtu/yzb/zkxx.ts b/lib/routes/sjtu/yzb/zkxx.ts index a90cbb62904a02..69ee5f8f943e30 100644 --- a/lib/routes/sjtu/yzb/zkxx.ts +++ b/lib/routes/sjtu/yzb/zkxx.ts @@ -47,8 +47,8 @@ async function handler(ctx) { .toArray() .map((elem) => ({ link: new URL(elem.attribs.href, pageUrl).href, - title: elem.attribs.title, - pubDate: parseDate($(elem.next).text().trim()), + title: $(elem).text(), + pubDate: parseDate($(elem.next?.next).text().trim()), })), }; } From 43c041ef11e0e91f437ca2bc3a8ff1e9b7e0dc63 Mon Sep 17 00:00:00 2001 From: CaoMeiYouRen <40430746+CaoMeiYouRen@users.noreply.github.com> Date: Sat, 27 Apr 2024 21:36:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(route):=20=E4=BF=AE=E5=A4=8D=20hellogit?= =?UTF-8?q?hub=20=E8=B7=AF=E7=94=B1=E9=94=99=E8=AF=AF=20(#15388)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(route): 修复 全国气象预警 为空的问题 * fix(route): 修复 hellogithub 路由错误 * fix(route): 优化 HelloGitHub title * fix(route): 修复 hellogithub 路由 * fix: revert changes on readable-social --------- --- lib/routes/hellogithub/index.ts | 4 +- lib/routes/hellogithub/report.ts | 3 +- lib/routes/hellogithub/volume.ts | 63 ++++++++++++++++++++------------ 3 files changed, 43 insertions(+), 27 deletions(-) diff --git a/lib/routes/hellogithub/index.ts b/lib/routes/hellogithub/index.ts index 7050f35d50fbec..c5093e5e3524fe 100644 --- a/lib/routes/hellogithub/index.ts +++ b/lib/routes/hellogithub/index.ts @@ -15,7 +15,7 @@ const sorts = { }; export const route: Route = { - path: ['/article/:sort?/:id?', '/:sort?/:id?'], + path: ['/article/:sort?/:id?'], categories: ['programming'], example: '/hellogithub/article', parameters: { sort: '排序方式,见下表,默认为 `hot`,即热门', id: '标签 id,可在对应标签页 URL 中找到,默认为全部标签' }, @@ -61,7 +61,7 @@ async function handler(ctx) { const $ = load(tagResponse.data); - tag = $('meta[property="og:title"]').attr('content').split(' ').pop(); + tag = $('meta[property="og:title"]')?.attr('content')?.split(' ').pop(); buildId = tagResponse.data.match(/"buildId":"(.*?)",/)[1]; } diff --git a/lib/routes/hellogithub/report.ts b/lib/routes/hellogithub/report.ts index 9b9e77ccdea5ec..734e98e3b8bdc9 100644 --- a/lib/routes/hellogithub/report.ts +++ b/lib/routes/hellogithub/report.ts @@ -15,7 +15,8 @@ const types = { export const route: Route = { path: ['/ranking/:type?', '/report/:type?'], - name: 'Unknown', + example: '/hellogithub/ranking', + name: '榜单报告', maintainers: ['moke8', 'nczitzk'], handler, description: `| 编程语言 | 服务器 | 数据库 | diff --git a/lib/routes/hellogithub/volume.ts b/lib/routes/hellogithub/volume.ts index 8f675c7f622375..34bd20a219b2b0 100644 --- a/lib/routes/hellogithub/volume.ts +++ b/lib/routes/hellogithub/volume.ts @@ -10,6 +10,8 @@ const md = MarkdownIt({ html: true, }); import { load } from 'cheerio'; +import cache from '@/utils/cache'; +import { config } from '@/config'; art.defaults.imports.render = function (string) { return md.render(string); @@ -17,12 +19,14 @@ art.defaults.imports.render = function (string) { export const route: Route = { path: ['/month', '/volume'], - name: 'Unknown', - maintainers: ['moke8', 'nczitzk'], + example: '/hellogithub/volume', + name: '月刊', + maintainers: ['moke8', 'nczitzk', 'CaoMeiYouRen'], handler, }; -async function handler() { +async function handler(ctx) { + const limit: number = Number.parseInt(ctx.req.query('limit')) || 10; const rootUrl = 'https://hellogithub.com'; const apiUrl = 'https://api.hellogithub.com/v1/periodical/'; @@ -30,33 +34,44 @@ async function handler() { method: 'get', url: apiUrl, }); - const current = periodicalResponse.data.volumes[0].num; - const currentUrl = `${rootUrl}/periodical/volume/${current}`; - const buildResponse = await got({ - method: 'get', - url: currentUrl, - }); + const volumes = periodicalResponse.data.volumes.slice(0, limit); - const $ = load(buildResponse.data); + const items = await Promise.all( + volumes.map(async (volume) => { + const current = volume.num; + const currentUrl = `${rootUrl}/periodical/volume/${current}`; + const key = `hellogithub:${currentUrl}`; + return await cache.tryGet( + key, + async () => { + const buildResponse = await got({ + method: 'get', + url: currentUrl, + }); - const text = $('#__NEXT_DATA__').text(); - const response = JSON.parse(text); - const data = response.props; - const id = data.pageProps.volume.current_num; + const $ = load(buildResponse.data); - const items = [ - { - title: `No.${id}`, - link: `${rootUrl}/periodical/volume/${id}`, - description: art(path.join(__dirname, 'templates/volume.art'), { - data: data.pageProps.volume.data, - }), - }, - ]; + const text = $('#__NEXT_DATA__').text(); + const response = JSON.parse(text); + const data = response.props; + const id = data.pageProps.volume.current_num; + return { + title: `《HelloGitHub》第 ${id} 期`, + link: `${rootUrl}/periodical/volume/${id}`, + description: art(path.join(__dirname, 'templates/volume.art'), { + data: data.pageProps.volume.data, + }), + }; + }, + config.cache.routeExpire, + false + ); + }) + ); return { title: 'HelloGithub - 月刊', - link: currentUrl, + link: 'https://hellogithub.com/periodical', item: items, }; }