feat: add national association of colleges and employers blog (#6542)

This commit is contained in:
Ethan Shen
2020-12-28 17:06:22 +00:00
committed by GitHub
parent cac6f75472
commit 9b2d2c97bb
4 changed files with 80 additions and 0 deletions
+3
View File
@@ -3766,6 +3766,9 @@ router.get('/sciencenet/blog/:type?/:time?/:sort?', require('./routes/sciencenet
// DailyArt
router.get('/dailyart/:language?', require('./routes/dailyart/index'));
// National Association of Colleges and Employers
router.get('/nace/blog/:sort?', require('./routes/nace/blog'));
// Caixin Latest
router.get('/caixin/latest', require('./routes/caixin/latest'));
+53
View File
@@ -0,0 +1,53 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const sort = ctx.params.sort || '';
const rootUrl = 'https://community.naceweb.org';
const currentUrl = `${rootUrl}/browse/blogs/${sort}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.BlogTitle')
.slice(0, 10)
.map((_, item) => {
item = $(item);
const link = item.attr('href');
const split = link.split('/');
return {
link,
title: item.text(),
pubDate: new Date(`${split[5]}-${split[6]}-${split[7]}`).toUTCString(),
};
})
.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('.blogs-block .col-md-12').html();
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};