feat(route): byteclicks (#11743)

* feat(route): byteclicks

* docs: fix paramsDesc
This commit is contained in:
Tony 2023-02-01 02:21:54 +07:00 committed by GitHub
parent 31c633abf8
commit 4567e3a6eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 102 additions and 0 deletions

View File

@ -4628,6 +4628,16 @@ QueryString:
</Route>
## 字节点击
### 首页
<Route author="TonyRL" example="/byteclicks" path="/byteclicks" radar="1" />
### 标签
<Route author="TonyRL" example="/byteclicks/tag/人工智能" path="/byteclicks/tag/:tag" radar="1" :paramsDesc="['标签可在URL中找到']"/>
## 自由微信
### 公众号

View File

@ -0,0 +1,22 @@
const got = require('@/utils/got');
const { parseItem } = require('./utils');
const baseUrl = 'https://byteclicks.com';
module.exports = async (ctx) => {
const { data } = await got(`${baseUrl}/wp-json/wp/v2/posts`, {
searchParams: {
per_page: ctx.query.limit ? parseInt(ctx.query.limit) : 100,
},
});
const items = parseItem(data);
ctx.state.data = {
title: '字节点击 - 聚合全球优质资源,跟踪世界前沿科技',
description:
'byteclicks.com 最专业的前沿科技网站。聚合全球优质资源跟踪世界前沿科技精选推荐一些很棒的互联网好资源好工具好产品。寻找有前景好项目、找论文、找报告、找数据、找课程、找电子书上byteclicksbyteclicks.com是投资人、科研学者、学生每天必看的网站。',
image: 'https://byteclicks.com/wp-content/themes/RK-Blogger/images/wbolt.ico',
link: baseUrl,
item: items,
};
};

View File

@ -0,0 +1,4 @@
module.exports = {
'/': ['TonyRL'],
'/tag/:tag': ['TonyRL'],
};

View File

@ -0,0 +1,19 @@
module.exports = {
'byteclicks.com': {
_name: '字节点击',
'.': [
{
title: '首页',
docs: 'https://docs.rsshub.app/new-media.html#zi-jie-dian-ji',
source: ['/'],
target: '/byteclicks',
},
{
title: '标签',
docs: 'https://docs.rsshub.app/new-media.html#zi-jie-dian-ji',
source: ['/tag/:tag'],
target: '/byteclicks/tag/:tag',
},
],
},
};

View File

@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/', require('./index'));
router.get('/tag/:tag', require('./tag'));
};

30
lib/v2/byteclicks/tag.js Normal file
View File

@ -0,0 +1,30 @@
const got = require('@/utils/got');
const { parseItem } = require('./utils');
const baseUrl = 'https://byteclicks.com';
module.exports = async (ctx) => {
const { tag } = ctx.params;
const { data: search } = await got(`${baseUrl}/wp-json/wp/v2/tags`, {
searchParams: {
search: tag,
per_page: 100,
},
});
const tagData = search.find((item) => item.name === tag);
const { data } = await got(`${baseUrl}/wp-json/wp/v2/posts`, {
searchParams: {
per_page: ctx.query.limit ? parseInt(ctx.query.limit) : 100,
tags: tagData.id,
},
});
const items = parseItem(data);
ctx.state.data = {
title: `${tagData.name} - 字节点击`,
image: 'https://byteclicks.com/wp-content/themes/RK-Blogger/images/wbolt.ico',
link: tagData.link,
item: items,
};
};

View File

@ -0,0 +1,13 @@
const { parseDate } = require('@/utils/parse-date');
const parseItem = (data) =>
data.map((item) => ({
title: item.title.rendered,
description: item.content.rendered,
pubDate: parseDate(item.date_gmt),
link: item.link,
}));
module.exports = {
parseItem,
};