From 7fda7a25399af8236d7a32154a76addffaeffa07 Mon Sep 17 00:00:00 2001 From: DaoXuan <116349858+dx2331lxz@users.noreply.github.com> Date: Sat, 14 Dec 2024 02:22:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E6=96=B0=E5=A2=9E=E5=8D=9A?= =?UTF-8?q?=E5=AE=A2=E9=81=93=E5=AE=A3=E7=9A=84=E7=AA=9D=20(#17890)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 尝试 * /daoxuan * 修改example * Update lib/routes/daoxuan/rss.ts --------- --- lib/routes/daoxuan/namespace.ts | 7 ++++++ lib/routes/daoxuan/rss.ts | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 lib/routes/daoxuan/namespace.ts create mode 100644 lib/routes/daoxuan/rss.ts diff --git a/lib/routes/daoxuan/namespace.ts b/lib/routes/daoxuan/namespace.ts new file mode 100644 index 00000000000000..19ae3d23a55788 --- /dev/null +++ b/lib/routes/daoxuan/namespace.ts @@ -0,0 +1,7 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '道宣的窝', + url: 'daoxuan.cc', + lang: 'zh-CN', +}; diff --git a/lib/routes/daoxuan/rss.ts b/lib/routes/daoxuan/rss.ts new file mode 100644 index 00000000000000..46b847728d86e2 --- /dev/null +++ b/lib/routes/daoxuan/rss.ts @@ -0,0 +1,43 @@ +import { Route } from '@/types'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/', + categories: ['blog'], + example: '/daoxuan', + radar: [ + { + source: ['daoxuan.cc/'], + }, + ], + name: '推荐阅读文章', + maintainers: ['dx2331lxz'], + url: 'daoxuan.cc/', + handler, +}; + +async function handler() { + const url = 'https://daoxuan.cc/'; + const response = await got({ method: 'get', url }); + const $ = load(response.data); + const items = $('div.recent-post-item') + .toArray() + .map((item) => { + item = $(item); + const a = item.find('a.article-title').first(); + const timeElement = item.find('time').first(); + return { + title: a.attr('title'), + link: `https://daoxuan.cc${a.attr('href')}`, + pubDate: parseDate(timeElement.attr('datetime')), + description: a.attr('title'), + }; + }); + return { + title: '道宣的窝', + link: url, + item: items, + }; +}