feat(route): add x410 news (#7339)

Co-authored-by: NeverBehave <gayhub@never.pet>
This commit is contained in:
Ethan Shen
2021-08-12 15:24:32 +08:00
committed by GitHub
parent ae51da7cae
commit f5ff75c543
4 changed files with 61 additions and 0 deletions

View File

@@ -339,6 +339,12 @@ Refer to [#minecraft](/en/game.html#minecraft)
<RouteEn author="cnzgray" example="/typora/changelog" path="/typora/changelog"/> <RouteEn author="cnzgray" example="/typora/changelog" path="/typora/changelog"/>
## X410
### News
<RouteEn author="nczitzk" example="/x410/news" path="/x410/news"/>
## Xiaomi.eu ## Xiaomi.eu
### ROM Releases ### ROM Releases

View File

@@ -432,6 +432,12 @@ pageClass: routes
<Route author="nczitzk" example="/typora/changelog-dev/macOS" path="/typora/changelog-dev/:os" :paramsDesc="['操作系统类型, 可选 `macOS``Windows``Linux`,默认为 `macOS`']"/> <Route author="nczitzk" example="/typora/changelog-dev/macOS" path="/typora/changelog-dev/:os" :paramsDesc="['操作系统类型, 可选 `macOS``Windows``Linux`,默认为 `macOS`']"/>
## X410
### News
<Route author="nczitzk" example="/x410/news" path="/x410/news"/>
## xclient.info ## xclient.info
### 应用更新 ### 应用更新

View File

@@ -4158,6 +4158,8 @@ router.get('/tanchinese/:category?', require('./routes/tanchinese'));
// Harvard // Harvard
router.get('/harvard/health/blog', require('./routes/universities/harvard/health/blog')); router.get('/harvard/health/blog', require('./routes/universities/harvard/health/blog'));
// X410
router.get('/x410/news', require('./routes/x410/news'));
// 恩山无线论坛 // 恩山无线论坛
router.get('/right/forum/:id?', require('./routes/right/forum')); router.get('/right/forum/:id?', require('./routes/right/forum'));

47
lib/routes/x410/news.js Normal file
View File

@@ -0,0 +1,47 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = 'https://x410.dev';
const currentUrl = `${rootUrl}/news`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.entry-title a')
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: item.attr('href'),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('.fusion-content-tb').html();
item.pubDate = Date.parse(content('meta[property="article:published_time"]').attr('content'));
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};