diff --git a/lib/routes/changelog.js b/lib/routes/changelog.js index 632fc719d2..53ce989338 100644 --- a/lib/routes/changelog.js +++ b/lib/routes/changelog.js @@ -2,13 +2,27 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); module.exports = async (ctx) => { + var 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://cn.eagle.cool/changelog', + url: `https://${language}.eagle.cool/changelog`, headers: { - Referer: `https://cn.eagle.cool/`, + Referer: `https://${language}.eagle.cool/`, }, }); @@ -20,33 +34,38 @@ module.exports = async (ctx) => { ctx.state.data = { // 源标题 - title: 'Eagle 更新日志', + title: `Eagle ${changelog}`, // 源链接 - link: 'https://cn.eagle.cool/changelog', + link: `https://${language}.eagle.cool/changelog`, // 源说明 - description: `Eagle 更新日志`, + description: `Eagle ${changelog}`, - // 遍历此前获取的数据 + //遍历此前获取的数据 item: list && list.map((index, item) => { item = $(item); // 对获取的日期进行格式化处理 function getDate() { - const str = item.find('.date').text(); - const patt = /[0-9]\d*/g; - let result; + var str = item.find('.date').text(); let date = ""; - while ((result = patt.exec(str)) !== null) { - date += result + '-'; + if (language === "cn" || language === "tw") { + var patt = /[0-9]\d*/g; + var result; + while ((result = patt.exec(str)) !== null) { + date += result + '-'; + } + date = date.replace(/-$/g, ""); + } else if (language === "en") { + date = str.replace(/RELEASED/g, ""); } - return date.replace(/-$/g, ""); + return date; } return { title: item.find('.ver').text(), description: item.find('.logs').html(), - link: 'https://cn.eagle.cool/changelog', + link: `https://${language}.eagle.cool/changelog`, pubDate: new Date(getDate()).toUTCString(), }; })