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

This commit is contained in:
Ethan Shen 2020-12-29 01:06:22 +08:00 committed by GitHub
parent cac6f75472
commit 9b2d2c97bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 80 additions and 0 deletions

View File

@ -215,6 +215,18 @@ Provides a better reading experience (full text articles) over the official one.
<RouteEn author="Cerebrater" example="/matters/author/az" path="/matters/author/:uid" :paramsDesc="['Author id, can be found at author\'s homepage url']" radar="1" rssbud="1"/>
## National Association of Colleges and Employers
### Blog
<RouteEn author="nczitzk" example="/nace/blog" path="/nace/blog/:sort?" :paramsDesc="['Sort, see below, Most Recent by default']">
| Most Recent | Top Rated | Most Read |
| - | - | - |
| | top-blogs | mostreadblogs |
</RouteEn>
## Nautilus
### Topics

View File

@ -1404,6 +1404,18 @@ column 为 third 时可选的 category:
</Route>
## 美国大学和雇主协会
### 博客
<Route author="nczitzk" example="/nace/blog" path="/nace/blog/:sort?" :paramsDesc="['排序,见下表,默认为 Most Recent']">
| Most Recent | Top Rated | Most Read |
| ----------- | --------- | ------------- |
| | top-blogs | mostreadblogs |
</Route>
## 梅斯医学 MedSci
### 推荐

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
lib/routes/nace/blog.js Normal file
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,
};
};