diff --git a/docs/program-update.md b/docs/program-update.md index a2dafca86a..706791de63 100644 --- a/docs/program-update.md +++ b/docs/program-update.md @@ -439,3 +439,6 @@ pageClass: routes ### 消息通知 + +### 更新日志 + diff --git a/lib/router.js b/lib/router.js index e9f57e3871..2da4052374 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3780,7 +3780,10 @@ router.get('/nace/blog/:sort?', require('./routes/nace/blog')); // Caixin Latest router.get('/caixin/latest', require('./routes/caixin/latest')); -// SimpRead +// SimpRead-消息通知 router.get('/simpread/notice', require('./routes/simpread/notice')); +// SimpRead-更新日志 +router.get('/simpread/changelog', require('./routes/simpread/changelog')); + module.exports = router; diff --git a/lib/routes/simpread/changelog.js b/lib/routes/simpread/changelog.js new file mode 100644 index 0000000000..d7ad05d766 --- /dev/null +++ b/lib/routes/simpread/changelog.js @@ -0,0 +1,77 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const url = 'https://simpread.pro/changelog.html'; + const response = await got.get(url); + const data = response.data; + const $ = cheerio.load(data); + ctx.state.data = { + title: 'SimpRead 更新日志', + link: url, + description: $('body > div.container.changelog > div.desc').html(), + item: $('.version') + .map((index, item) => { + const year = $(item).find('.year').html(); + const month_day = $(item).find('.day').html(); + let version = ''; + let detail = ''; + + // 结构异化-收个version与后续version不同级 + if (index === 0) { + // 版本名称处理 + version = $($(item).find('.num > a')[0]).clone().children().remove().end().text(); + // detail处理 + detail = $($(item).find('.details')[0]); + } else { + // 版本名称处理 + version = $(item).find('.num > a').clone().children().remove().end().text(); + // detail处理 + detail = $(item).find('.details'); + } + if (version === '') { + version = $(item).find('.num').clone().children().remove().end().text(); + } + let version_type = $(item).find('.num > a > i').attr('class'); + // 部分结构不一致处理 + if (version_type === undefined) { + version_type = $(item).find('.num > i').attr('class'); + } + if (version_type.indexOf('chrome') !== -1) { + version_type = 'Chrome'; + } + if (version_type.indexOf('apple') !== -1) { + version_type = 'Safari'; + } + if (version_type.indexOf('code') !== -1) { + version_type = 'UserScript'; + } + if (version_type.indexOf('firefox') !== -1) { + version_type = 'Firefox'; + } + + $(detail) + .find('li') + .map((index, item) => { + const level = $(item).find('span').attr('class'); + if (level !== undefined) { + if (level.indexOf('empty') !== -1) { + $(item).wrap(''); + } else { + $(item).find('span').append('
'); + } + } + return {}; + }); + + return { + description: $(detail).html(), + link: url, + pubDate: `${year}-${month_day.replace('.', '-')} 00:00:00 GMT`, + title: `${version_type}${version}`, + author: 'SimpRead', + }; + }) + .get(), + }; +};