From 271efc81ba67ad05943ea1110949695c8081d423 Mon Sep 17 00:00:00 2001 From: Yorkin Yuan Date: Wed, 2 Mar 2022 22:13:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20=E9=B1=BC=E5=A1=98=E7=83=AD?= =?UTF-8?q?=E6=A6=9C=E4=BF=AE=E5=A4=8D=E4=B8=8E=E4=BC=98=E5=8C=96=20(#9214?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 鱼塘热榜图片显示,日期错误 * fix: use parseDate util * fix: use single quotes * fix: art template * update: gif file extension --- lib/routes/mofish/index.js | 30 ++++++++++++++------- lib/routes/mofish/templates/description.art | 4 +++ 2 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 lib/routes/mofish/templates/description.art diff --git a/lib/routes/mofish/index.js b/lib/routes/mofish/index.js index aff04e293c..924e0cb438 100644 --- a/lib/routes/mofish/index.js +++ b/lib/routes/mofish/index.js @@ -1,4 +1,7 @@ const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); module.exports = async (ctx) => { const id = ctx.params.id; @@ -13,17 +16,26 @@ module.exports = async (ctx) => { const data = response.data.Data.data; - const title = `鱼塘热榜`; + const title = '鱼塘热榜'; ctx.state.data = { title, - link: `https://mo.fish/`, - description: title, - item: data.map((item) => ({ - title: item.Title, - pubDate: new Date(item.releaseTime).toUTCString(), - link: item.Url, - guid: item.id, - })), + link: 'https://mo.fish/', + item: data.map((item) => { + const isImage = Number(id) === 136 && item.Url.endsWith('.gif'); + const description = isImage + ? art(path.join(__dirname, 'templates/description.art'), { + imageUrl: item.Url, + }) + : title; + + return { + title: item.Title, + description, + pubDate: parseDate(item.CreateTime * 1000), + link: item.Url, + guid: item.id, + }; + }), }; }; diff --git a/lib/routes/mofish/templates/description.art b/lib/routes/mofish/templates/description.art new file mode 100644 index 0000000000..27cc225271 --- /dev/null +++ b/lib/routes/mofish/templates/description.art @@ -0,0 +1,4 @@ +

+ +
+

\ No newline at end of file