feat(route): 新增铅笔道文章列表 (#18155)
* feat(pencilnews): 新增铅笔道文章列表
* 📝 docs(pencilnews/index.ts): 更新维护者信息
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
@@ -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',
|
||||
};
|
||||
Reference in New Issue
Block a user