From cb551b45e437fb36d13ba2d32cfd80c9811fb363 Mon Sep 17 00:00:00 2001 From: pseudoyu Date: Thu, 5 Dec 2024 01:08:26 +0800 Subject: [PATCH] fix(route/hbr): remove Latest from type --- lib/routes/hbr/topic.ts | 45 +++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/lib/routes/hbr/topic.ts b/lib/routes/hbr/topic.ts index d7bac1912aea4d..adbce1b657380d 100644 --- a/lib/routes/hbr/topic.ts +++ b/lib/routes/hbr/topic.ts @@ -1,14 +1,25 @@ import { Route } from '@/types'; import cache from '@/utils/cache'; -import got from '@/utils/got'; +import ofetch from '@/utils/ofetch'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; export const route: Route = { path: '/topic/:topic?/:type?', - categories: ['new-media'], - example: '/hbr/topic/leadership', - parameters: { topic: 'Topic, can be found in URL, Leadership by default', type: 'Type, see below, Latest by default' }, + categories: ['new-media', 'popular'], + example: '/hbr/topic/Leadership/Popular', + parameters: { + topic: 'Topic, can be found in URL, Leadership by default', + type: { + description: 'Type, see below, Popular by default', + options: [ + { value: 'Popular', label: 'Popular' }, + { value: 'From the Store', label: 'From the Store' }, + { value: 'For You', label: 'For You' }, + ], + default: 'Popular', + }, + }, features: { requireConfig: false, requirePuppeteer: false, @@ -23,11 +34,11 @@ export const route: Route = { }, ], name: 'Topic', - maintainers: ['nczitzk'], + maintainers: ['nczitzk', 'pseudoyu'], handler, - description: `| LATEST | POPULAR | FROM THE STORE | FOR YOU | - | ------ | ------- | -------------- | ------- | - | Latest | Popular | From the Store | For You | + description: `| POPULAR | FROM THE STORE | FOR YOU | + | ------- | -------------- | ------- | + | Popular | From the Store | For You | :::tip Click here to view [All Topics](https://hbr.org/topics) @@ -35,18 +46,15 @@ export const route: Route = { }; async function handler(ctx) { - const topic = ctx.req.param('topic') ?? 'leadership'; - const type = ctx.req.param('type') ?? 'Latest'; + const topic = ctx.req.param('topic') ?? 'Leadership'; + const type = ctx.req.param('type') ?? 'Popular'; const rootUrl = 'https://hbr.org'; const currentUrl = `${rootUrl}/topic/${topic}`; - const response = await got({ - method: 'get', - url: currentUrl, - }); + const response = await ofetch(currentUrl); - const $ = load(response.data); + const $ = load(response); const list = $(`stream-content[data-stream-name="${type}"]`) .find('.stream-item') @@ -65,12 +73,9 @@ async function handler(ctx) { const items = await Promise.all( list.map((item) => cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); + const detailResponse = await ofetch(item.link); - const content = load(detailResponse.data); + const content = load(detailResponse); item.description = content('.article-body, article[itemprop="description"]').html(); item.pubDate = parseDate(content('meta[property="article:published_time"]').attr('content'));