From c63a8e998a28b236eac2c7d7b5f41b45c9014b84 Mon Sep 17 00:00:00 2001 From: nczitzk Date: Wed, 6 Jan 2021 22:35:47 +0800 Subject: [PATCH] feat: add semiconductor industry association latest news --- docs/en/new-media.md | 7 ++++ docs/new-media.md | 6 +++ lib/router.js | 3 ++ lib/routes/semiconductors/latest-news.js | 48 ++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 lib/routes/semiconductors/latest-news.js diff --git a/docs/en/new-media.md b/docs/en/new-media.md index 070815cbe..2074c9342 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -260,6 +260,7 @@ This route provides a flexible plan with full text content to subscribe specific ### Blog + ## Quanta Magazine ### Archive @@ -273,6 +274,12 @@ Compared to the official one, this feed: +## Semiconductor Industry Association + +### Latest News + + + ## Simons Foundation ### Articles diff --git a/docs/new-media.md b/docs/new-media.md index dea896d57..3897d5a2a 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1370,6 +1370,12 @@ column 为 third 时可选的 category: +## 美国半导体行业协会 + +### 新闻 + + + ## 美国大学和雇主协会 ### 博客 diff --git a/lib/router.js b/lib/router.js index 5bb0f656c..e02e3e11e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3780,4 +3780,7 @@ router.get('/nace/blog/:sort?', require('./routes/nace/blog')); // Caixin Latest router.get('/caixin/latest', require('./routes/caixin/latest')); +// Semiconductor Industry Association +router.get('/semiconductors/latest-news', require('./routes/semiconductors/latest-news')); + module.exports = router; diff --git a/lib/routes/semiconductors/latest-news.js b/lib/routes/semiconductors/latest-news.js new file mode 100644 index 000000000..cd1787121 --- /dev/null +++ b/lib/routes/semiconductors/latest-news.js @@ -0,0 +1,48 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.semiconductors.org'; + const currentUrl = `${rootUrl}/news-events/latest-news`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('h3') + .slice(0, 15) + .map((_, item) => { + item = $(item).parent(); + 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('#main').html(); + item.pubDate = new Date(content('meta[property="article:published_time"]').attr('content')).toUTCString(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};