From f5ff75c543a88d268d682f021a4d4d6b5a36280e Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Thu, 12 Aug 2021 15:24:32 +0800 Subject: [PATCH] feat(route): add x410 news (#7339) Co-authored-by: NeverBehave --- docs/en/program-update.md | 6 +++++ docs/program-update.md | 6 +++++ lib/router.js | 2 ++ lib/routes/x410/news.js | 47 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 lib/routes/x410/news.js diff --git a/docs/en/program-update.md b/docs/en/program-update.md index 105b252de2..dd0a673164 100644 --- a/docs/en/program-update.md +++ b/docs/en/program-update.md @@ -339,6 +339,12 @@ Refer to [#minecraft](/en/game.html#minecraft) +## X410 + +### News + + + ## Xiaomi.eu ### ROM Releases diff --git a/docs/program-update.md b/docs/program-update.md index e93a2016c7..eed45b3c05 100644 --- a/docs/program-update.md +++ b/docs/program-update.md @@ -432,6 +432,12 @@ pageClass: routes +## X410 + +### News + + + ## xclient.info ### 应用更新 diff --git a/lib/router.js b/lib/router.js index ae1e818cf7..10505425c5 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4158,6 +4158,8 @@ router.get('/tanchinese/:category?', require('./routes/tanchinese')); // Harvard 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')); diff --git a/lib/routes/x410/news.js b/lib/routes/x410/news.js new file mode 100644 index 0000000000..4d4646079a --- /dev/null +++ b/lib/routes/x410/news.js @@ -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, + }; +};