Skip to content

Commit

Permalink
feat(route): 新增铅笔道文章列表 (DIYgod#18155)
Browse files Browse the repository at this point in the history
* feat(pencilnews): 新增铅笔道文章列表

* 📝 docs(pencilnews/index.ts): 更新维护者信息
  • Loading branch information
defp authored Jan 18, 2025
1 parent e280d41 commit 277b5cf
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
70 changes: 70 additions & 0 deletions lib/routes/pencilnews/index.ts
Original file line number Diff line number Diff line change
@@ -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,
};
}
9 changes: 9 additions & 0 deletions lib/routes/pencilnews/namespace.ts
Original file line number Diff line number Diff line change
@@ -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',
};

0 comments on commit 277b5cf

Please sign in to comment.