mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-11 15:47:48 +08:00
feat: add latexstudio (#2869)
This commit is contained in:
@@ -185,6 +185,12 @@ pageClass: routes
|
|||||||
|
|
||||||
<Route author="Dectinc DIYgod" example="/keep/user/556b02c1ab59390afea671ea" path="/keep/user/:id" :paramsDesc="['Keep 用户 id']"/>
|
<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
|
## MobData
|
||||||
|
|
||||||
### 分析报告
|
### 分析报告
|
||||||
|
|||||||
@@ -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/sale', require('./routes/queshu/sale'));
|
||||||
router.get('/queshu/book/:bookid', require('./routes/queshu/book'));
|
router.get('/queshu/book/:bookid', require('./routes/queshu/book'));
|
||||||
|
|
||||||
|
// LaTeX 开源小屋
|
||||||
|
router.get('/latexstudio/home', require('./routes/latexstudio/home'));
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
66
lib/routes/latexstudio/home.js
Normal file
66
lib/routes/latexstudio/home.js
Normal 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,
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user