Merge pull request #6624 from nczitzk/feature/semiconductors

feat: add semiconductor industry association latest news
This commit is contained in:
NeverBehave
2021-01-10 21:17:55 -05:00
committed by GitHub
4 changed files with 64 additions and 0 deletions
+7
View File
@@ -268,6 +268,7 @@ This route provides a flexible plan with full text content to subscribe specific
### Blog
<RouteEn author="nczitzk" example="/polar/blog" path="/polar/blog"/>
## Quanta Magazine
### Archive
@@ -281,6 +282,12 @@ Compared to the official one, this feed:
</RouteEn>
## Semiconductor Industry Association
### Latest News
<RouteEn author="nczitzk" example="/semiconductors/latest-news" path="/semiconductors/latest-news"/>
## Simons Foundation
### Articles
+6
View File
@@ -1438,6 +1438,12 @@ column 为 third 时可选的 category:
</Route>
## 美国半导体行业协会
### 新闻
<Route author="nczitzk" example="/semiconductors/latest-news" path="/semiconductors/latest-news"/>
## 美国大学和雇主协会
### 博客
+3
View File
@@ -3790,6 +3790,9 @@ 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'));
// VOA News
router.get('/voa/day-photos', require('./routes/voa/day-photos'));
+48
View File
@@ -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,
};
};