Merge pull request #78 from zytomorrow/xueqiu_comments

fix: 雪球股票评论正文使用art模板,日期解析调整
This commit is contained in:
zytomorrow
2021-07-28 04:30:50 -05:00
committed by GitHub
+21 -7
View File
@@ -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 = `
<a href='https://xueqiu.com/u/{{item.user.id}}'>
<div style="font-weight: bold;">{{item.user.screen_name}}:</div>
</a>
<hr/>
{{item.text}}
<br/>
{{if item.retweeted_status}}
<hr style="border:1 dashed #987cb9" />
{{item.retweeted_status.text}}
{{else}}
<hr/>
{{/if}}
<div style="text-align:right">
----来源于:{{item.source}}
</div>`;
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 = `<a href="https://xueqiu.com/u/${item.user.id}"><div style='font-weight: bold;'>${item.user.screen_name}:</div></a><hr/>${item.text}<br/><HR style="border:1 dashed #987cb9" width="80%" color=#987cb9 SIZE=1>${item.retweeted_status.text}<hr/><div style="text-align:right">----来源于:${item.source}</div>`;
} else {
description = `<a href="https://xueqiu.com/u/${item.user.id}"><div style='font-weight: bold;'>${item.user.screen_name}:</div></a><hr/>${item.text}<br/><hr/><div style="text-align:right">----来源于:${item.source}</div>`;
}
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,
};
}),