Skip to content

Commit

Permalink
1. Change the categories;
Browse files Browse the repository at this point in the history
2. Remove the maximum number of route customization. Use the common parameter limit instead;
3. Correct the example path;
4. Correct the name;
  • Loading branch information
Lyunvy committed Oct 4, 2024
1 parent 3c36c5a commit 599da8f
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions lib/routes/xbookcn/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { load } from 'cheerio';
import cache from '@/utils/cache';

export const route: Route = {
path: '/:label?/:max?', // 路由路径
categories: ['other'], // 分类
example: '/xbookcn/:label?', // 示例路径
parameters: { label: '按名称分类,详见https://blog.xbookcn.net/p/all.html', max: '最大条数' }, // 参数
path: '/:label?', // 路由路径
categories: ['reading'], // 分类
example: '/xbookcn/精选作品', // 示例路径
parameters: { label: '按名称分类,详见https://blog.xbookcn.net/p/all.html' }, // 参数
features: {
requireConfig: false,
requirePuppeteer: false,
Expand All @@ -16,11 +16,11 @@ export const route: Route = {
supportPodcast: false,
supportScihub: false,
},
name: 'xbookcn', // 源名称
name: '短篇', // 源名称
maintainers: ['Lyunvy'], // 维护者
handler: async (ctx) => {
const { label = '精选作品', max = '20' } = ctx.req.param(); // 从请求参数中获取 label
const url = `https://blog.xbookcn.net/search/label/${label}?max-results=${max}`; // 使用反引号构建 URL
const { label = '精选作品' } = ctx.req.param(); // 从请求参数中获取 label
const url = `https://blog.xbookcn.net/search/label/${label}`; // 使用反引号构建 URL
const response = await ofetch(url); // 请求源链接
const $ = load(response); // 加载 HTML

Expand All @@ -36,23 +36,24 @@ export const route: Route = {
});

const items = await Promise.all(
list.map(async (item) =>
// 使用缓存以避免重复请求
await cache.tryGet(item.link, async () => {
const response = await ofetch(item.link); // 请求文章链接
const $ = load(response); // 加载文章页面
list.map(
async (item) =>
// 使用缓存以避免重复请求
await cache.tryGet(item.link, async () => {
const response = await ofetch(item.link); // 请求文章链接
const $ = load(response); // 加载文章页面

// 获取文章的完整描述
item.description = $('.post-body.entry-content').html() || '无内容'; // 抓取指定内容
// 获取文章的完整描述
item.description = $('.post-body.entry-content').html() || '无内容'; // 抓取指定内容

// 获取分类信息
const categories = $('.post-labels a')
.toArray()
.map((el) => $(el).text().trim());
item.category = categories; // 添加多个分类信息
// 获取分类信息
const categories = $('.post-labels a')
.toArray()
.map((el) => $(el).text().trim());
item.category = categories; // 添加多个分类信息

return item; // 返回带有描述和分类的文章对象
})
return item; // 返回带有描述和分类的文章对象
})
)
);

Expand Down

0 comments on commit 599da8f

Please sign in to comment.