forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): 新增铅笔道文章列表 (DIYgod#18155)
* feat(pencilnews): 新增铅笔道文章列表 * 📝 docs(pencilnews/index.ts): 更新维护者信息
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}; |