mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
Add(route): add 链新闻abmedia (#8862)
Co-authored-by: DIYgod <diy.d.god@gmail.com>
This commit is contained in:
@@ -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>
|
||||
|
||||
## 雷峰网
|
||||
|
||||
### 最新文章
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/abmedia/:category?': ['Fatpandac'],
|
||||
};
|
||||
@@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/index', require('./index'));
|
||||
router.get('/:category?', require('./category'));
|
||||
};
|
||||
Reference in New Issue
Block a user