Merge branch 'master' into uestc_sice_notice

This commit is contained in:
Henry Wang
2020-12-28 17:06:35 +00:00
committed by GitHub
11 changed files with 198 additions and 6 deletions
+1 -1
View File
@@ -40,7 +40,7 @@ const calculateValue = () => {
listenInaddrAny: envs.LISTEN_INADDR_ANY || 1, // 是否允许公网连接,取值 0 1
requestRetry: parseInt(envs.REQUEST_RETRY) || 2, // 请求失败重试次数
// 是否显示 Debug 信息,取值 boolean 'false' 'key' ,取值为 'false' false 时永远不显示,取值为 'key' 时带上 ?debug=key 显示
debugInfo: envs.DEBUG_INFO || true,
debugInfo: envs.DEBUG_INFO || false,
disallowRobot: envs.DISALLOW_ROBOT !== '0' && envs.DISALLOW_ROBOT !== 'false',
titleLengthLimit: parseInt(envs.TITLE_LENGTH_LIMIT) || 150,
redis: {
+6
View File
@@ -3768,4 +3768,10 @@ 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'));
module.exports = router;
+71
View File
@@ -0,0 +1,71 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const li_r = await got({
method: 'get',
url: 'http://finance.caixin.com/2020-11-03/101622309.html',
});
const $ = cheerio.load(li_r.data);
const list = $('div.columnBox a[name="new_artical"]~ul.list li');
const tasks = [];
list.map((_index, li) => $(li).find('a').first().attr('href'))
.filter((_index, link) => link.indexOf('fm.caixin.com') === -1 && link.indexOf('video.caixin.com') === -1) // content filter
.each((_index, link) => {
const entry = ctx.cache.tryGet(link, async () => {
const entry_r = await got.get(link);
const $ = cheerio.load(entry_r.data);
// title
const h1 = $('div#conTit h1').text();
// desc items
const subhead = $('div#subhead.subhead').text();
let pic_url = $('img.cx-img-loader').attr('src');
if (pic_url === undefined) {
pic_url = $('img.cx-img-loader').attr('data-src');
}
const pic_alt = $('dl.media_pic dd').text();
const content = $('div#Main_Content_Val.text').html();
/*
const [, count] =
$('a.box_titlecontent.cost-uibtn')
.text()
.match(/本文共计(\d+)字/) || [];
if (count !== 0 && count !== undefined) {
content = `${content}<blockquote><p>此乃财新通收费文章,全文共计${count}字。</p></blockquote>`;
}
*/
// desc
let desc;
if (pic_url === undefined) {
desc = `<blockquote><p>${subhead}</p></blockquote>${content}`;
} else {
desc = `<blockquote><p>${subhead}</p></blockquote><img src="${pic_url}" alt="${pic_alt}">${content}`;
}
// time
const [, year, month, day, hour, minute] = $('div#artInfo.artInfo')
.text()
.match(/(\d+)年(\d+)月(\d+)日 *(\d+):(\d+)/);
const time = new Date(`${year}-${month}-${day}T${hour}:${minute}:00+0800`).toUTCString();
return {
title: h1,
description: desc,
pubDate: time,
link: link,
};
});
tasks.push(entry);
});
const rss = await Promise.all(tasks);
ctx.state.data = {
title: '财新网 - 最新文章',
link: 'http://www.caixin.com/',
item: rss,
};
};
+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,
};
};