feat(route): add Aqara Community (#12338)
* feat(route): add Aqara Community * style: crlf to lf * docs: add keyword parameter * fix: merge conflict ---------
This commit is contained in:
parent
b921c04bfb
commit
774a4feb52
|
|
@ -78,6 +78,10 @@ pageClass: routes
|
|||
|
||||
## Aqara
|
||||
|
||||
### Community
|
||||
|
||||
<Route author="nczitzk" example="/aqara/community" path="/aqara/community/:id?/:keyword?" :paramsDesc="['分类 id,可在对应分类页 URL 中找到,默认为全部', '关键字,默认为空']"/>
|
||||
|
||||
### News
|
||||
|
||||
<Route author="nczitzk" example="/aqara/news" path="/aqara/news"/>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id ?? '';
|
||||
const keyword = ctx.params.keyword ?? '';
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 100;
|
||||
|
||||
const rootUrl = 'https://community.aqara.com';
|
||||
const apiUrl = `${rootUrl}/api/v2/feeds?limit=${limit}&platedetail_id=${id}&keyword=${keyword}&all=1`;
|
||||
const currentUrl = `${rootUrl}/pc/#/post${id ? `?id=${id}` : ''}`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: apiUrl,
|
||||
});
|
||||
|
||||
const items = response.data.map((item) => ({
|
||||
title: item.feed_title,
|
||||
link: `${rootUrl}/pc/#/post/postDetail/${item.id}`,
|
||||
description: item.feed_content,
|
||||
pubDate: parseDate(item.created_at),
|
||||
author: item.user.nickname,
|
||||
}));
|
||||
|
||||
ctx.state.data = {
|
||||
title: 'Aqara社区',
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
allowEmpty: true,
|
||||
};
|
||||
};
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = {
|
||||
'/community/:id?/:keyword?': ['nczitzk'],
|
||||
'/news': ['nczitzk'],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,5 +9,13 @@ module.exports = {
|
|||
target: '/aqara/news',
|
||||
},
|
||||
],
|
||||
community: [
|
||||
{
|
||||
title: 'Community',
|
||||
docs: 'https://docs.rsshub.app/other.html#aqara-community',
|
||||
source: ['/pc', '/'],
|
||||
target: (params, url) => `/aqara/community/${new URL(url).searchParams.get('id')}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/community/:id?/:keyword?', require('./community'));
|
||||
router.get('/news', require('./news'));
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue