From 0b2b8e0e6676f97ec99f0bf8d39a8491f6da4d0d Mon Sep 17 00:00:00 2001 From: kjasn Date: Fri, 8 May 2026 21:12:00 +0800 Subject: [PATCH] feat(route/qwen): replace deprecated qwen blog route with new one (#21944) * feat: replace deprecated qwen blog route * fix: replace wrong field and add param desc * fix: remove unnecessary param * fix: use import type * refactor: qwen blog * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * error handling and tidy * tidy * fix: remove unnecessary header --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- lib/routes/qwen/blog.ts | 54 +++++++++++++++++ lib/routes/{qwenlm => qwen}/namespace.ts | 4 +- lib/routes/qwenlm/blog.ts | 76 ------------------------ 3 files changed, 56 insertions(+), 78 deletions(-) create mode 100644 lib/routes/qwen/blog.ts rename lib/routes/{qwenlm => qwen}/namespace.ts (61%) delete mode 100644 lib/routes/qwenlm/blog.ts diff --git a/lib/routes/qwen/blog.ts b/lib/routes/qwen/blog.ts new file mode 100644 index 000000000..2faca2d2d --- /dev/null +++ b/lib/routes/qwen/blog.ts @@ -0,0 +1,54 @@ +import { load } from 'cheerio'; + +import type { Data, DataItem, Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { parseDate } from '@/utils/parse-date'; + +export const buildBlogItem = (item: any, base: string): DataItem => { + const $ = load(item.content || item.extra.introduction || ''); + const content = $('.post-content').html() ?? (item.extra.introduction || ''); + + return { + title: item.title, + image: item.extra.cover_small, + pubDate: parseDate(item.extra.date), + author: item.extra.author, + link: `${base}/blog?id=${item.path}`, + description: content, + category: item.extra.tags, + }; +}; + +export const route: Route = { + path: '/blog/:lang?', + categories: ['programming'], + example: '/qwen/blog', + parameters: { + lang: '语言,`zh-CN`, `en-US`', + }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: 'Blog', + maintainers: ['Kjasn'], + handler: async (ctx): Promise => { + const base = 'https://qwen.ai'; + const { lang = 'zh-CN' } = ctx.req.param(); + + const blogUrl = `${base}/api/v2/article/retrieval?language=${lang}&type=qwen_ai`; + + const response = await ofetch(blogUrl); + const articles = response.data?.articles; + + return { + title: 'Qwen Blog', + link: `${base}/research`, + item: (articles || []).map((item: any) => buildBlogItem(item, base)), + }; + }, +}; diff --git a/lib/routes/qwenlm/namespace.ts b/lib/routes/qwen/namespace.ts similarity index 61% rename from lib/routes/qwenlm/namespace.ts rename to lib/routes/qwen/namespace.ts index a1a077702..df14749ac 100644 --- a/lib/routes/qwenlm/namespace.ts +++ b/lib/routes/qwen/namespace.ts @@ -1,6 +1,6 @@ import type { Namespace } from '@/types'; export const namespace: Namespace = { - name: 'Qwen Blog', - url: 'qwenlm.github.io', + name: 'Qwen Research', + url: 'qwen.ai', }; diff --git a/lib/routes/qwenlm/blog.ts b/lib/routes/qwenlm/blog.ts deleted file mode 100644 index befc24a9f..000000000 --- a/lib/routes/qwenlm/blog.ts +++ /dev/null @@ -1,76 +0,0 @@ -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: '/blog/:lang?', - categories: ['blog'], - example: '/qwenlm/blog/zh', - parameters: { lang: 'Blog language' }, - features: { - requireConfig: false, - requirePuppeteer: false, - antiCrawler: false, - supportBT: false, - supportPodcast: false, - supportScihub: false, - }, - radar: [ - { - source: ['qwenlm.github.io/blog/', 'qwenlm.github.io/:lang/blog/'], - target: '/qwenlm/blog/:lang', - }, - ], - name: 'Blog', - maintainers: ['Kjasn'], - handler: async (ctx) => { - const { lang } = ctx.req.param(); - - const blogUrl = lang ? `https://qwenlm.github.io/${lang}/blog` : 'https://qwenlm.github.io/blog'; - - const response = await ofetch(blogUrl); - const $ = load(response); - - // get blog list - const list = $('article.post-entry') - .toArray() - .map((item) => { - item = $(item); - - const dateString = item - .find('.entry-footer span') - .attr('title') - .trim() - .replace(/\+0800$/, ''); - // const pubDate = timezone(parseDate(dateString, 'YYYY-MM-DD HH:mm:ss ZZ'), +8); - const pubDate = parseDate(dateString); - - return { - title: item.find('header.entry-header h2').text().trim(), - link: item.find('.entry-link').attr('href'), - pubDate, - }; - }); - - // get blog content - const items = await Promise.all( - list.map((item) => - cache.tryGet(item.link, async () => { - const response = await ofetch(item.link); - const $ = load(response); - item.description = $('main').html(); - return item; - }) - ) - ); - - return { - title: 'Qwen Blog', - link: blogUrl, - item: items, - }; - }, -};