From 74cf0399bd5195e199dc3841d5815fb8b5dff1c8 Mon Sep 17 00:00:00 2001 From: zytomorrow Date: Mon, 19 Jul 2021 12:01:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=9B=AA=E7=90=83=E8=82=A1=E7=A5=A8?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E6=AD=A3=E6=96=87=E4=BD=BF=E7=94=A8art?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=EF=BC=8C=E6=97=A5=E6=9C=9F=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/xueqiu/stock_comments.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/routes/xueqiu/stock_comments.js b/lib/routes/xueqiu/stock_comments.js index ac6c46c67f..47e4550c9f 100644 --- a/lib/routes/xueqiu/stock_comments.js +++ b/lib/routes/xueqiu/stock_comments.js @@ -1,5 +1,24 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const template = require('art-template'); +const { parseDate } = require('@/utils/parse-date'); + +const description_template = ` + +
{{item.user.screen_name}}:
+
+
+{{item.text}} +
+{{if item.retweeted_status}} +
+{{item.retweeted_status.text}} +{{else}} +
+{{/if}} +
+ ----来源于:{{item.source}} +
`; module.exports = async (ctx) => { const id = ctx.params.id; @@ -30,16 +49,11 @@ module.exports = async (ctx) => { if (item.quote_cards) { link = item.quote_cards[0].target_url; } - let description = ''; - if (item.retweeted_status) { - description = `
${item.user.screen_name}:

${item.text}

${item.retweeted_status.text}
----来源于:${item.source}
`; - } else { - description = `
${item.user.screen_name}:

${item.text}

----来源于:${item.source}
`; - } + const description = template.render(description_template, { item: item }); return { title: item.title !== '' ? item.title : item.text.replace(/<[^>]+>/g, '').slice(0, titleLength), description: description, - pubDate: new Date(item.created_at).toUTCString(), + pubDate: parseDate(item.created_at), link, }; }),