feat: add latexstudio (#2869)

This commit is contained in:
Cloud
2019-08-17 12:32:34 +08:00
committed by DIYgod
parent 8650501d9f
commit 5516dac61f
3 changed files with 75 additions and 0 deletions

View File

@@ -185,6 +185,12 @@ pageClass: routes
<Route author="Dectinc DIYgod" example="/keep/user/556b02c1ab59390afea671ea" path="/keep/user/:id" :paramsDesc="['Keep 用户 id']"/>
## LaTeX 开源小屋
### 首页
<Route author="kt286" example="/latexstudio/home" path="/latexstudio/home"/>
## MobData
### 分析报告

View File

@@ -1631,4 +1631,7 @@ router.get('/sf/sffq-announce', require('./routes/sf/sffq-announce'));
router.get('/queshu/sale', require('./routes/queshu/sale'));
router.get('/queshu/book/:bookid', require('./routes/queshu/book'));
// LaTeX 开源小屋
router.get('/latexstudio/home', require('./routes/latexstudio/home'));
module.exports = router;

View File

@@ -0,0 +1,66 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { addNoReferrer } = require('@/utils/common-utils');
module.exports = async (ctx) => {
const res = await got({
method: 'get',
url: 'https://www.latexstudio.net/',
});
const $ = cheerio.load(res.data);
const list = $('div.article-latest').find('div.item');
const ProcessFeed = async (link) => {
const detail = await got({
method: 'get',
url: link,
});
const $ = cheerio.load(detail.data);
$('.tac').remove();
addNoReferrer($, '.article-content');
const author = $('.article-meta .item:last-child')
.text()
.replace('稿源:', '');
const description = $('.article-content').html();
return { description, author };
};
const items = await Promise.all(
list
.slice(0, 10)
.map(async (index, item) => {
const $item = $(item);
const originalUrl = $item
.find('h2')
.find('a')
.attr('href')
.replace('http', 'https');
const cache = await ctx.cache.get(originalUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const { description, author } = await ProcessFeed(originalUrl);
const single = {
title: `${$item
.find('a.cat')
.text()
.trim()} - ${$item.find('h2', 'a').text()}`,
link: originalUrl,
description,
author,
};
ctx.cache.set(originalUrl, JSON.stringify(single));
return Promise.resolve(single);
})
.get()
);
ctx.state.data = {
title: 'LaTeX 开源小屋',
link: 'http://www.latexstudio.net/',
item: items,
};
};