feat(route): add Eagle route and radar rules (#6946)

* Create changelog.js

* Update router.js

* Update radar-rules.js

* Update program-update.md

* Update program-update.md

* [CodeFactor] Apply fixes

[ci skip] [skip ci]

* Update changelog.js

* Update changelog.js

* Update changelog.js

* [CodeFactor] Apply fixes to commit aa75389

[ci skip] [skip ci]

* Update program-update.md

* Update router.js

* Update program-update.md

* Update radar-rules.js

* Update program-update.md

* Update program-update.md

* Update radar-rules.js

* Update program-update.md

* Update program-update.md

* Update program-update.md

* Update radar-rules.js

* Update radar-rules.js

* Rename lib/routes/changelog.js to lib/routes/eagle/changelog.js

Co-authored-by: codefactor-io <support@codefactor.io>
This commit is contained in:
小虎故洞 2021-02-25 05:49:27 +08:00 committed by GitHub
parent d112044560
commit 17860306fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 132 additions and 0 deletions

View File

@ -2731,6 +2731,33 @@
},
],
},
'eagle.cool': {
_name: 'Eagle',
cn: [
{
title: '更新日志',
docs: 'https://docs.rsshub.app/program-update.html#eagle',
source: '/changelog',
target: '/eagle/changelog/cn',
},
],
tw: [
{
title: '更新日誌',
docs: 'https://docs.rsshub.app/program-update.html#eagle',
source: '/changelog',
target: '/eagle/changelog/tw',
},
],
en: [
{
title: 'Release Notes',
docs: 'https://docs.rsshub.app/program-update.html#eagle',
source: '/changelog',
target: '/eagle/changelog/en',
},
],
},
'furaffinity.net': {
_name: 'Fur Affinity',
www: [

View File

@ -120,6 +120,20 @@ The owner of the official image fills in the library, for example: https://rsshu
:::
## Eagle
### Changelog
<RouteEn author="tigercubden" example="/eagle/changelog/en" path="/eagle/changelog/:language?" :paramsDesc="['Language, see list, default to be `cn`']" radar="1">
Language
| Simplified Chinese | Traditional Chinese | English |
| ------ | -------- | -------- |
| cn | tw | en |
<RouteEn/>
## Everything
### Changes

View File

@ -158,6 +158,20 @@ pageClass: routes
:::
## Eagle
### 更新日志
<Route author="tigercubden" example="/eagle/changelog" path="/eagle/changelog/:language?" :paramsDesc="['语言,选项见下表,默认为 `cn`']" radar="1">
语言
| 简体中文 | 繁体中文 | 英文 |
| ------ | -------- | -------- |
| cn | tw | en |
</Route>
## Everything
### Changes

View File

@ -3968,4 +3968,7 @@ router.get('/iyiou', require('./routes/iyiou'));
// 香港商报
router.get('/hkcd/pdf', require('./routes/hkcd/pdf'));
// Eagle
router.get('/eagle/changelog/:language?', require('./routes/eagle/changelog'));
module.exports = router;

View File

@ -0,0 +1,74 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
let language = ctx.params.language;
let changelog = '';
// 如果为空或选项以外的值,则设置默认值
if (language === undefined || !(language === 'tw' || language === 'en')) {
language = 'cn';
changelog = '更新日志';
}
if (language === 'tw') {
changelog = '更新日誌';
}
if (language === 'en') {
changelog = 'Release Notes';
}
// 发起 HTTP GET 请求
const response = await got({
method: 'get',
url: `https://${language}.eagle.cool/changelog`,
headers: {
Referer: `https://${language}.eagle.cool/`,
},
});
// 使用 cheerio 加载返回的 HTML
const data = response.data;
const $ = cheerio.load(data);
const list = $('.version');
ctx.state.data = {
// 源标题
title: `Eagle ${changelog}`,
// 源链接
link: `https://${language}.eagle.cool/changelog`,
// 源说明
description: `Eagle ${changelog}`,
// 遍历此前获取的数据
item:
list &&
list.map((index, item) => {
item = $(item);
// 对获取的日期进行格式化处理
function getDate() {
const str = item.find('.date').text();
let date = "";
if (language === "cn" || language === "tw") {
const patt = /[0-9]\d*/g;
let result;
while ((result = patt.exec(str)) !== null) {
date += result + '-';
}
date = date.replace(/-$/g, "");
} else if (language === "en") {
date = str.replace(/RELEASED/g, "");
}
return date;
}
return {
title: item.find('.ver').text(),
description: item.find('.logs').html(),
link: `https://${language}.eagle.cool/changelog`,
pubDate: new Date(getDate()).toUTCString(),
};
})
.get(),
};
};