From 277b5cf080eac3c05a18d8b552d6d0d8c7e4b3b3 Mon Sep 17 00:00:00 2001
From: lidashuang
Date: Sat, 18 Jan 2025 14:28:02 +0800
Subject: [PATCH] =?UTF-8?q?feat(route):=20=E6=96=B0=E5=A2=9E=E9=93=85?=
=?UTF-8?q?=E7=AC=94=E9=81=93=E6=96=87=E7=AB=A0=E5=88=97=E8=A1=A8=20(#1815?=
=?UTF-8?q?5)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat(pencilnews): 新增铅笔道文章列表
* 📝 docs(pencilnews/index.ts): 更新维护者信息
---
lib/routes/pencilnews/index.ts | 70 ++++++++++++++++++++++++++++++
lib/routes/pencilnews/namespace.ts | 9 ++++
2 files changed, 79 insertions(+)
create mode 100644 lib/routes/pencilnews/index.ts
create mode 100644 lib/routes/pencilnews/namespace.ts
diff --git a/lib/routes/pencilnews/index.ts b/lib/routes/pencilnews/index.ts
new file mode 100644
index 00000000000000..f39f9a687bb5c2
--- /dev/null
+++ b/lib/routes/pencilnews/index.ts
@@ -0,0 +1,70 @@
+import { Route } from '@/types';
+import cache from '@/utils/cache';
+import got from '@/utils/got';
+import { load } from 'cheerio';
+import { parseDate } from '@/utils/parse-date';
+
+export const route: Route = {
+ path: '/',
+ categories: ['new-media'],
+ example: '/pencilnews',
+ parameters: {},
+ features: {
+ requireConfig: false,
+ requirePuppeteer: false,
+ antiCrawler: false,
+ supportBT: false,
+ supportPodcast: false,
+ supportScihub: false,
+ },
+ name: '文章列表',
+ maintainers: ['defp'],
+ handler,
+ description: '获取铅笔道最新文章',
+};
+
+async function handler() {
+ const baseUrl = 'https://www.pencilnews.cn';
+ const apiUrl = 'https://api.pencilnews.cn/articles';
+
+ const response = await got(apiUrl, {
+ searchParams: {
+ page: 0,
+ page_size: 20,
+ },
+ });
+
+ const {
+ data: { articles },
+ } = response.data;
+
+ const items = await Promise.all(
+ articles.map((article) => {
+ const info = article.article_info;
+ const articleId = info.article_id;
+ const link = `${baseUrl}/p/${articleId}.html`;
+
+ return cache.tryGet(link, async () => {
+ const detailResponse = await got(link);
+ const $ = load(detailResponse.data);
+ const content = $('.article_content').html();
+
+ return {
+ title: info.title,
+ description: content,
+ link,
+ author: article.author?.profile?.name || '',
+ pubDate: parseDate(info.create_at, 'YYYY-MM-DD HH:mm:ss'),
+ category: [],
+ guid: articleId,
+ };
+ });
+ })
+ );
+
+ return {
+ title: '铅笔道',
+ link: baseUrl,
+ item: items,
+ };
+}
diff --git a/lib/routes/pencilnews/namespace.ts b/lib/routes/pencilnews/namespace.ts
new file mode 100644
index 00000000000000..7de632d5c9b6a5
--- /dev/null
+++ b/lib/routes/pencilnews/namespace.ts
@@ -0,0 +1,9 @@
+import type { Namespace } from '@/types';
+
+export const namespace: Namespace = {
+ name: '铅笔道',
+ url: 'www.pencilnews.cn',
+ categories: ['new-media'],
+ description: '铅笔道是一家专注于泛互联网领域的科技媒体',
+ lang: 'zh-CN',
+};