feat(route): add Aqara News (#12337)

* feat(route): add Aqara News

* docs: add news

* fix typo
This commit is contained in:
Ethan Shen
2023-04-18 03:12:13 +08:00
committed by GitHub
parent e00b5aafb7
commit b921c04bfb
5 changed files with 78 additions and 0 deletions
+6
View File
@@ -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
### 搜索结果
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/news': ['nczitzk'],
};
+53
View File
@@ -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,
};
};
+13
View File
@@ -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',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/news', require('./news'));
};