feat: add ditto clipboard manager changes (#6490)

This commit is contained in:
Ethan Shen 2020-12-24 02:11:57 +08:00 committed by GitHub
parent 3426f8a1f4
commit 4d4e6fb6d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 0 deletions

View File

@ -96,6 +96,12 @@ For example: `https://www.curseforge.com/sc2/assets/taylor-mouses-stuff/files` t
</RouteEn>
## Ditto clipboard manager
### Changes
<RouteEn author="nczitzk" example="/ditto/changes" path="/ditto/changes/:type?" :paramsDesc="['Type, `beta` is an option']"/>
## Docker Hub
### Image New Build

View File

@ -152,6 +152,12 @@ pageClass: routes
</Route>
## Ditto clipboard manager
### Changes
<Route author="nczitzk" example="/ditto/changes" path="/ditto/changes/:type?" :paramsDesc="['类型,可选 `beta`']"/>
## Docker Hub
### 镜像有新 Build

View File

@ -3733,10 +3733,14 @@ router.get('/dayone/blog', require('./routes/dayone/blog'));
// 滴答清单
router.get('/dida365/habit/checkins', require('./routes/dida365/habit-checkins'));
// Ditto clipboard manager
router.get('/ditto/changes/:type?', require('./routes/ditto/changes'));
// iDaily 每日环球视野
router.get('/idaily/today', require('./routes/idaily/index'));
// 北屋
router.get('/northhouse/:category?', require('./routes/northhouse/index'));
module.exports = router;

View File

@ -0,0 +1,36 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const type = ctx.params.type || '';
const rootUrl = 'https://ditto-cp.sourceforge.io';
const currentUrl = `${rootUrl}/${type === '' ? 'changeHistory.php' : `${type}/changes.php`}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(type === '' ? response.data : `<div class="post">${response.data.split('\r\n').join('</div><div class="post">')}</div>`);
const items = $('.post')
.map((_, item) => {
item = $(item);
const title = type === '' ? item.find('.title').text() : item.text();
return {
title,
link: currentUrl,
pubDate: new Date(title.split(' ')[type === '' ? 1 : 0]).toUTCString(),
description: type === '' ? item.find('.entry').html() : `<p>${item.text()}</p>`,
};
})
.get();
ctx.state.data = {
title: `Ditto clipboard manager ${type === '' ? '' : `(${type}) `}changes`,
link: currentUrl,
item: items,
};
};