feat: add monotype featured article (#4836)
This commit is contained in:
parent
7fc19772b5
commit
8f91cd763e
|
|
@ -67,6 +67,12 @@ pageClass: routes
|
|||
|
||||
</Route>
|
||||
|
||||
## Monotype
|
||||
|
||||
### Featured Article
|
||||
|
||||
<Route author="nczitzk" example="/monotype/article" path="/monotype/article" />
|
||||
|
||||
## Sun Creature
|
||||
|
||||
### Works
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ pageClass: routes
|
|||
|
||||
<Route author="Diffumist" example="/ahut/cstzgg" path="/ahut/cstzgg" />
|
||||
|
||||
|
||||
## 安徽农业大学
|
||||
|
||||
### 计算机学院
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
})
|
||||
)
|
||||
),
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue