Skip to content

Commit 7fda7a2

Browse files
authored
feat(route): 新增博客道宣的窝 (#17890)
* 尝试 * /daoxuan * 修改example * Update lib/routes/daoxuan/rss.ts ---------
1 parent a5deeb3 commit 7fda7a2

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

lib/routes/daoxuan/namespace.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { Namespace } from '@/types';
2+
3+
export const namespace: Namespace = {
4+
name: '道宣的窝',
5+
url: 'daoxuan.cc',
6+
lang: 'zh-CN',
7+
};

lib/routes/daoxuan/rss.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Route } from '@/types';
2+
import got from '@/utils/got';
3+
import { load } from 'cheerio';
4+
import { parseDate } from '@/utils/parse-date';
5+
6+
export const route: Route = {
7+
path: '/',
8+
categories: ['blog'],
9+
example: '/daoxuan',
10+
radar: [
11+
{
12+
source: ['daoxuan.cc/'],
13+
},
14+
],
15+
name: '推荐阅读文章',
16+
maintainers: ['dx2331lxz'],
17+
url: 'daoxuan.cc/',
18+
handler,
19+
};
20+
21+
async function handler() {
22+
const url = 'https://daoxuan.cc/';
23+
const response = await got({ method: 'get', url });
24+
const $ = load(response.data);
25+
const items = $('div.recent-post-item')
26+
.toArray()
27+
.map((item) => {
28+
item = $(item);
29+
const a = item.find('a.article-title').first();
30+
const timeElement = item.find('time').first();
31+
return {
32+
title: a.attr('title'),
33+
link: `https://daoxuan.cc${a.attr('href')}`,
34+
pubDate: parseDate(timeElement.attr('datetime')),
35+
description: a.attr('title'),
36+
};
37+
});
38+
return {
39+
title: '道宣的窝',
40+
link: url,
41+
item: items,
42+
};
43+
}

0 commit comments

Comments
 (0)