From 9f8e967c8a30d545a08127e01b264eb4cad41218 Mon Sep 17 00:00:00 2001 From: Kjasn Date: Wed, 17 Sep 2025 18:37:28 +0800 Subject: [PATCH] feat(route): add qwen blog (#20064) * feat(route): add qwen blog * handle date and remove redundant category --- lib/routes/qwenlm/blog.ts | 75 ++++++++++++++++++++++++++++++++++ lib/routes/qwenlm/namespace.ts | 6 +++ 2 files changed, 81 insertions(+) create mode 100644 lib/routes/qwenlm/blog.ts create mode 100644 lib/routes/qwenlm/namespace.ts diff --git a/lib/routes/qwenlm/blog.ts b/lib/routes/qwenlm/blog.ts new file mode 100644 index 000000000..5c7016823 --- /dev/null +++ b/lib/routes/qwenlm/blog.ts @@ -0,0 +1,75 @@ +import { Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { load } from 'cheerio'; +import cache from '@/utils/cache'; +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, + }; + }, +}; diff --git a/lib/routes/qwenlm/namespace.ts b/lib/routes/qwenlm/namespace.ts new file mode 100644 index 000000000..a1a077702 --- /dev/null +++ b/lib/routes/qwenlm/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Qwen Blog', + url: 'qwenlm.github.io', +};