fix: latexstudio articles (#4845)
This commit is contained in:
parent
6d657eeae2
commit
f02e01c004
|
|
@ -11,8 +11,8 @@ pageClass: routes
|
|||
<Route author="zcx1218029121" example="/adnmb/20" path="/adnmb/:pid" :paramsDesc="['板块 id 或者板块名称,例如`/adnmb/20`等价于`/adnmb/欢乐恶搞`,现有板块请参考下表']" >
|
||||
|
||||
| 时间线 | 综合版 1 | 围炉 | 欢乐恶搞 | 速报 2 | 推理 | 跑团 | 技术宅 | 料理 | 猫版 | 音乐 | 考试 | 社畜 |
|
||||
| ----- | -------- | ---- | -------- | ------ | ---- | ---- | ------ | ---- | ---- | ---- | ---- | ---- |
|
||||
| -1 | 4 | 120 | 20 | 121 | 11 | 111 | 30 | 32 | 40 | 35 | 56 | 110 |
|
||||
| ------ | -------- | ---- | -------- | ------ | ---- | ---- | ------ | ---- | ---- | ---- | ---- | ---- |
|
||||
| -1 | 4 | 120 | 20 | 121 | 11 | 111 | 30 | 32 | 40 | 35 | 56 | 110 |
|
||||
|
||||
| 科学 | 文学 | 创意 | 姐妹 1 | 数码 | 女装 | 日记 | 圈内 | 都市怪谈 | 买买买 | 动画 | 漫画 | 美漫 | 国漫 | 小说 |
|
||||
| ---- | ---- | ---- | ------ | ---- | ---- | ---- | ---- | -------- | ------ | ---- | ---- | ---- | ---- | ---- |
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ pageClass: routes
|
|||
|
||||
### 首页
|
||||
|
||||
<Route author="kt286" example="/latexstudio/home" path="/latexstudio/home"/>
|
||||
<Route author="kt286 nczitzk" example="/latexstudio/home" path="/latexstudio/home"/>
|
||||
|
||||
## LeeMeng
|
||||
|
||||
|
|
|
|||
|
|
@ -1,55 +1,44 @@
|
|||
const url = require('url');
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
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 rootUrl = 'https://www.latexstudio.net/articles/';
|
||||
|
||||
const ProcessFeed = async (link) => {
|
||||
const detail = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
});
|
||||
const $ = cheerio.load(detail.data);
|
||||
$('.tac').remove();
|
||||
const author = $('.article-meta .item:last-child').text().replace('稿源:', '');
|
||||
const description = $('.article-content').html();
|
||||
return { description, author };
|
||||
};
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: rootUrl,
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('div.article-list')
|
||||
.find('h3.article-title')
|
||||
.slice(0, 20)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
const a = item.find('a');
|
||||
return {
|
||||
title: a.text(),
|
||||
link: url.resolve(rootUrl, a.attr('href')),
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
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()
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const res = await got({ method: 'get', url: item.link });
|
||||
const content = cheerio.load(res.data);
|
||||
item.pubDate = new Date(content('div.entry-meta ul li').eq(3).text().replace('发布日期:', '')).toUTCString();
|
||||
item.description = content('div.article-text').html();
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: 'LaTeX 开源小屋',
|
||||
link: 'http://www.latexstudio.net/',
|
||||
link: 'https://www.latexstudio.net/articles/',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue