Add(route): add Codeforces contests (#8815)

Co-authored-by: HuangWei <huangwei.a180285@gmail.com>
Co-authored-by: DIYgod <diy.d.god@gmail.com>
This commit is contained in:
Fatpandac
2022-01-23 04:10:59 +08:00
committed by GitHub
parent f04fa890b3
commit bc35a1e937
7 changed files with 79 additions and 0 deletions

View File

@@ -10,6 +10,12 @@ pageClass: routes
<Route author="nczitzk" example="/acm/amturingaward" path="/acm/amturingaward"/>
## Codeforces
### Latest contests
<RouteEn author="Fatpandac" example="/codeforces/contests" path="/codeforces/contests"/>
## AtCoder
### Present Contests

View File

@@ -24,6 +24,12 @@ pageClass: routes
> AlgoCasts 需要付费订阅RSS 仅做更新提醒,不含付费内容.
## Codeforces
#### 最新比赛
<Route author="Fatpandac" example="/codeforces/contests" path="/codeforces/contests"/>
## AtCoder
### Present Contests

View File

@@ -0,0 +1,37 @@
const got = require('@/utils/got');
const path = require('path');
const { art } = require('@/utils/render');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const contestAPI = 'https://codeforces.com/api/contest.list';
module.exports = async (ctx) => {
const contestsData = await got.get(contestAPI).json();
const contests = contestsData.result;
const items = contests
.filter((contests) => contests.phase === 'BEFORE')
.map((contest) => {
const title = String(contest.name);
const description = art(path.join(__dirname, 'templates/contest.art'), {
title,
startTime: timezone(parseDate(contest.startTimeSeconds * 1000), +0),
durationTime: contest.durationSeconds / 60,
relativeTime: Math.floor(contest.relativeTimeSeconds / 60),
type: contest.type,
});
return {
title,
description,
link: 'https://codeforces.com/contests/' + contest.id,
};
});
ctx.state.data = {
title: 'Codeforces - Contests',
link: 'https://codeforces.com/contests',
item: items,
};
};

View File

@@ -0,0 +1,3 @@
module.exports = {
'/contests': ['Fatpandac'],
};

View File

@@ -0,0 +1,13 @@
module.exports = {
'codeforces.com': {
_name: 'Codeforces',
www: [
{
title: '最新比赛',
docs: 'https://docs.rsshub.app/programming.html#codeforces-zui-xin-bi-sai',
source: ['/contests'],
target: '/codeforces/contests',
},
],
},
};

View File

@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/contests', require('./contests'));
};

View File

@@ -0,0 +1,11 @@
<text>比赛:{{ title }}</text>
<br>
<text>开始时间:{{ startTime }}</text>
<br>
<text>持续时间:{{ durationTime }} 分钟</text>
<br>
<text>相对时间:{{ relativeTime }} 分钟</text>
<br>
<text>比赛类型:{{ type }}</text>
<br>