feat: add monotype featured article (#4836)

This commit is contained in:
Ethan Shen 2020-05-22 16:18:51 +08:00 committed by GitHub
parent 7fc19772b5
commit 8f91cd763e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 1 deletions

View File

@ -67,6 +67,12 @@ pageClass: routes
</Route>
## Monotype
### Featured Article
<Route author="nczitzk" example="/monotype/article" path="/monotype/article" />
## Sun Creature
### Works

View File

@ -38,7 +38,6 @@ pageClass: routes
<Route author="Diffumist" example="/ahut/cstzgg" path="/ahut/cstzgg" />
## 安徽农业大学
### 计算机学院

View File

@ -2742,4 +2742,7 @@ router.get('/aljazeera/news', require('./routes/aljazeera/news'));
router.get('/pbc/goutongjiaoliu', require('./routes/pbc/goutongjiaoliu'));
router.get('/pbc/tradeAnnouncement', require('./routes/pbc/tradeAnnouncement'));
// Monotype
router.get('/monotype/article', require('./routes/monotype/article'));
module.exports = router;

View File

@ -0,0 +1,39 @@
const url = require('url');
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = 'https://www.monotype.com/resources';
const response = await got({
method: 'get',
url: rootUrl,
});
const $ = cheerio.load(response.data);
const list = $('h3.component-title')
.map((_, item) => {
item = $(item);
return {
title: item.find('a').text(),
link: url.resolve(rootUrl, item.find('a').attr('href')),
};
})
.get();
ctx.state.data = {
title: 'Monotype - Feature Articles',
link: rootUrl,
item: await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const res = await got({ method: 'get', url: item.link });
const content = cheerio.load(res.data);
item.pubDate = new Date(content('meta[itemprop="acquia_lift:published_date"]').attr('content') * 1000).toUTCString();
item.description = content('div.left-region').html();
return item;
})
)
),
};
};