feat: add 洛谷日报文章全文 (#5503)
This commit is contained in:
parent
7539783629
commit
757708ca95
|
|
@ -564,13 +564,11 @@ GitHub 官方也提供了一些 RSS:
|
|||
|
||||
### 日报
|
||||
|
||||
<Route author="LogicJake prnake" example="/luogu/daily" path="/luogu/daily/:id?" :paramsDesc="['年度日报所在帖子id,可在 URL 中找到,不填默认为2020年日报']">
|
||||
</Route>
|
||||
<Route author="LogicJake prnake nczitzk" example="/luogu/daily" path="/luogu/daily/:id?" :paramsDesc="['年度日报所在帖子id,可在 URL 中找到,不填默认为2020年日报']"/>
|
||||
|
||||
### 近期比赛
|
||||
|
||||
<Route author="prnake" example="/luogu/contest" path="/luogu/contest">
|
||||
</Route>
|
||||
<Route author="prnake" example="/luogu/contest" path="/luogu/contest"/>
|
||||
|
||||
## 码农俱乐部
|
||||
|
||||
|
|
|
|||
|
|
@ -13,16 +13,42 @@ module.exports = async (ctx) => {
|
|||
.map(function () {
|
||||
const info = {
|
||||
title: $(this).find('strong').text() || $(this).text(),
|
||||
description: $(this).html(),
|
||||
link: $(this).find('a').attr('href'),
|
||||
};
|
||||
return info;
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
out.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);
|
||||
const timeRegExp = new RegExp(/(?<=([1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d))/);
|
||||
|
||||
item.description = content('#article-content').html();
|
||||
|
||||
content('#article-content').remove();
|
||||
|
||||
const line = content
|
||||
.html()
|
||||
.split('\n')
|
||||
.find((line) => timeRegExp.test(line));
|
||||
|
||||
item.pubDate = new Date(line.match(timeRegExp)[1] + ' GMT+8').toUTCString();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: title,
|
||||
link: link,
|
||||
item: out,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue