Skip to content

Commit

Permalink
24/11/28 feat: routes/qbitai
Browse files Browse the repository at this point in the history
  • Loading branch information
Geraldxm committed Nov 28, 2024
1 parent bcc2a05 commit e1e6208
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
47 changes: 42 additions & 5 deletions lib/routes/qbitai/category.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Route } from '@/types';
import parser from '@/utils/rss-parser';

import ofetch from '@/utils/ofetch';
import cache from '@/utils/cache';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';

export const route: Route = {
Expand All @@ -22,7 +24,7 @@ export const route: Route = {
},
],
name: '分类',
maintainers: ['FuryMartin'],
maintainers: ['FuryMartin, Geraldxm'],
handler,
description: `| 资讯 | 数码 | 智能车 | 智库 | 活动 |
| ---- | -------- | ------ | ----- | ------- |
Expand All @@ -36,19 +38,54 @@ async function handler(ctx) {

const items = feed.items.map((item) => ({
title: item.title,
pubDate: parseDate(item.pubDate),
pubDate: parseDate(item.pubDate ?? ''),
link: item.link,
author: '量子位',
category: item.categories,
description: item['content:encoded'],
// 初始化 description 字段
description: '',
}));

// 使用 Promise.all 并发处理所有项目
await Promise.all(
items.map(async (item) => {
try {
// 尝试从缓存中获取 description
const cachedDescription = await cache.tryGet(`description:${item.link}`, async () => {
const response = await ofetch(item.link);
const $ = load(response);
// 获取文章内容,这里假设文章内容在 .article 类中
const articleHtml = $('.article').html();
return articleHtml || '';
});

// 设置 description 字段
item.description = cachedDescription;
} catch {
item.description = '内容获取失败';
}
})
);

return {
// 源标题
title: `量子位-${category}`,
title: `量子位 - ${category}`,
// 源链接
link: `https://www.qbitai.com/category/${category}`,
// 源文章
item: items,
};
}

/*
<item>
<title>刚刚,Kimi开源底层推理框架,1小时GitHub揽星1.2k</title>
<description/>
<link>https://www.qbitai.com/2024/11/225771.html</link>
<guid isPermaLink="false">https://www.qbitai.com/2024/11/225771.html</guid>
<pubDate>Thu, 28 Nov 2024 08:01:56 GMT</pubDate>
<author>量子位</author>
<category>资讯</category>
<category>Kimi</category>
</item>
*/
2 changes: 2 additions & 0 deletions lib/routes/qbitai/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: '量子位',
url: 'qbitai.com',
categories: ['new-media'],
lang: 'zh-CN',
description: '量子位是一个关注科技前沿、科学探索、智能硬件、人工智能、区块链、物联网、智能车、智库、活动等领域的科技媒体。',
};

0 comments on commit e1e6208

Please sign in to comment.