Add(route): add 链新闻abmedia (#8862)

Co-authored-by: DIYgod <diy.d.god@gmail.com>
This commit is contained in:
Fatpandac
2022-01-23 14:42:08 +00:00
committed by GitHub
co-authored by DIYgod
parent f61581d17d
commit 2673fae330
6 changed files with 98 additions and 0 deletions
+16
View File
@@ -2057,6 +2057,22 @@ column 为 third 时可选的 category:
<Route author="xyqfer" example="/laosiji/hotshow/128" path="/laosiji/hotshow/:id" :paramsDesc="['节目 id']"/>
## 链新闻 ABMedia
### 首页最新新闻
<Route author="Fatpandac" example="/abmedia/index" path="/abmedia/index"/>
### 类别
<Route author="Fatpandac" example="/abmedia/technology-development" path="/abmedia/:category?" :paramsDesc="['类别,默认为产品技术']">
参数可以从链接中拿到,如:
`https://www.abmedia.io/category/technology-development` 对应 `/abmedia/technology-development`
</Route>
## 雷峰网
### 最新文章
+30
View File
@@ -0,0 +1,30 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const rootUrl = 'https://www.abmedia.io';
const cateAPIUrl = `${rootUrl}/wp-json/wp/v2/categories`;
const postsAPIUrl = `${rootUrl}/wp-json/wp/v2/posts`;
const getCategoryId = async (category) => await got.get(`${cateAPIUrl}?slug=${category}`).then((res) => res.data[0].id);
module.exports = async (ctx) => {
const category = ctx.params.category ?? 'technology-development';
const limit = ctx.params.limit ?? 25;
const categoryId = await getCategoryId(category);
const response = await got.get(`${postsAPIUrl}?categories=${categoryId}&page=1&per_page=${limit}`);
const data = response.data;
const items = data.map((item) => ({
title: item.title.rendered,
link: item.link,
description: item.content.rendered,
pubDate: parseDate(item.date),
}));
ctx.state.data = {
title: `abmedia - ${category}`,
link: `${rootUrl}/category/${category}`,
item: items,
};
};
+26
View File
@@ -0,0 +1,26 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const rootUrl = 'https://www.abmedia.io';
const postsAPIUrl = `${rootUrl}/wp-json/wp/v2/posts`;
module.exports = async (ctx) => {
const limit = ctx.params.limit ?? 10;
const url = `${postsAPIUrl}?per_page=${limit}`;
const response = await got.get(url);
const data = response.data;
const items = data.map((item) => ({
title: item.title.rendered,
link: item.link,
description: item.content.rendered,
pubDate: parseDate(item.date),
}));
ctx.state.data = {
title: 'ABMedia - 最新消息',
link: rootUrl,
item: items,
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/abmedia/:category?': ['Fatpandac'],
};
+19
View File
@@ -0,0 +1,19 @@
module.exports = {
'abmedia.io': {
_name: 'abmedia.io',
www: [
{
title: '首页最新新闻',
docs: 'https://docs.rsshub.app/new-media.html#lian-xin-wen-abmedia-shou-ye-zui-xin-xin-wen',
source: ['/'],
target: '/abmedia/index',
},
{
title: '频道',
docs: 'https://docs.rsshub.app/new-media.html#lian-xin-wen-abmedia-lei-bie',
source: ['/category/:catehory'],
target: '/abmedia/:category',
},
],
},
};
+4
View File
@@ -0,0 +1,4 @@
module.exports = function (router) {
router.get('/index', require('./index'));
router.get('/:category?', require('./category'));
};