mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-25 10:14:31 +08:00
feat(route): add Aqara News (#12337)
* feat(route): add Aqara News * docs: add news * fix typo
This commit is contained in:
@@ -76,6 +76,12 @@ pageClass: routes
|
||||
|
||||
见 [#app-store-mac-app-store](/program-update.html#app-store-mac-app-store)
|
||||
|
||||
## Aqara
|
||||
|
||||
### News
|
||||
|
||||
<Route author="nczitzk" example="/aqara/news" path="/aqara/news"/>
|
||||
|
||||
## AutoTrader
|
||||
|
||||
### 搜索结果
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/news': ['nczitzk'],
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 35;
|
||||
|
||||
const rootUrl = 'https://www.aqara.com';
|
||||
const currentUrl = `${rootUrl}/news`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
let items = response.data
|
||||
.match(/parm.contentHerf = '(\d+)'/g)
|
||||
.slice(0, limit)
|
||||
.map((item) => ({
|
||||
link: `${rootUrl}/${item.match(/'(\d+)'/)[1]}`,
|
||||
}));
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.title = content('h4.fnt_56').last().text();
|
||||
item.description = content('.news_body').html();
|
||||
item.pubDate = parseDate(
|
||||
content('.news_date')
|
||||
.first()
|
||||
.text()
|
||||
.replace(/( {2}年 {2}| {2}月 {2})/g, '-')
|
||||
.replace(/ {2}日/, '')
|
||||
);
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '新闻动态 - Aqara 全屋智能',
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
'aqara.com': {
|
||||
_name: 'Aqara',
|
||||
'.': [
|
||||
{
|
||||
title: 'News',
|
||||
docs: 'https://docs.rsshub.app/other.html#aqara-news',
|
||||
source: ['/news', '/'],
|
||||
target: '/aqara/news',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/news', require('./news'));
|
||||
};
|
||||
Reference in New Issue
Block a user