feat: add anki changes (#5799)

Co-authored-by: Henry Wang <hi@henry.wang>
This commit is contained in:
Ethan Shen
2020-10-08 15:17:14 +01:00
committed by GitHub
co-authored by Henry Wang
parent 676f3fbb4e
commit bb3f9cde6b
4 changed files with 54 additions and 0 deletions
+6
View File
@@ -4,6 +4,12 @@ pageClass: routes
# Application Updates
## Anki
### Changes
<Route author="nczitzk" example="/anki/changes" path="/anki/changes"/>
## Apkpure
### Versions
+6
View File
@@ -14,6 +14,12 @@ pageClass: routes
</Route>
## Anki
### Changes
<Route author="nczitzk" example="/anki/changes" path="/anki/changes"/>
## Apkpure
### Versions
+3
View File
@@ -3260,6 +3260,9 @@ router.get('/appsales/:caty?/:time?', require('./routes/appsales/index'));
// CGTN
router.get('/cgtn/top', require('./routes/cgtn/top'));
// Anki
router.get('/anki/changes', require('./routes/anki/changes'));
// ABC News
router.get('/abc/:site?', require('./routes/abc/index.js'));
+39
View File
@@ -0,0 +1,39 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const md = require('markdown-it')({
html: true,
});
module.exports = async (ctx) => {
const rootUrl = 'https://changes.ankiweb.net';
const currentUrl = `${rootUrl}/README.md`;
const response = await got({
method: 'get',
url: currentUrl,
});
const html = md.render(response.data.replace(/# Changes in/g, '## Changes in').replace(/### Changes in/g, '## Changes in'));
const $ = cheerio.load(html.replace(/<h2>/g, '</div><div><h2>'));
const items = $('div')
.slice(0, 20)
.map((_, item) => {
item = $(item);
const h2 = item.find('h2');
const match = item.find('p').text().match('Released (.*).');
h2.remove();
return {
title: h2.text(),
description: item.html(),
link: `${rootUrl}/#/?id=changes-in-${h2.text().toLowerCase().split(' ').join('-').replace(/\./g, '')}`,
pubDate: match ? new Date(match[1].split(',')[0] + ' GMT+8').toUTCString() : '',
};
})
.get();
ctx.state.data = {
title: 'Changes - Anki',
link: rootUrl,
item: items,
};
};