rss: weibo format, remove "全文"; remove link icon; replace expression to text

This commit is contained in:
DIYgod 2018-07-13 17:25:35 +08:00
parent ed2a39e156
commit 1819a4bedf
No known key found for this signature in database
GPG Key ID: EC0B76A252D3EF67
2 changed files with 8 additions and 9 deletions

View File

@ -30,10 +30,11 @@ module.exports = async (ctx) => {
link: `http://weibo.com/${uid}/`,
description: `${name}的微博`,
item: response.data.data.cards.filter((item) => item.mblog && !item.mblog.isTop).map((item) => {
const title = item.mblog.text.replace(/<img.*?>/g, '[图片]').replace(/<.*?>/g, '');
const description = weiboUtils.format(item.mblog);
const title = description.replace(/<img.*?>/g, '[图片]').replace(/<.*?>/g, '');
return {
title: title.length > 24 ? title.slice(0, 24) + '...' : title,
description: weiboUtils.format(item.mblog),
description: description,
pubDate: weiboUtils.getTime(item.mblog.created_at),
link: `https://weibo.com/${uid}/${item.mblog.bid}`,
};

View File

@ -2,14 +2,12 @@ const weiboUtils = {
format: (status) => {
// 长文章的处理
let temp = (status.longText && status.longText.longTextContent.replace(/\n/g, '<br>')) || status.text || '';
// 表情图标转换为文字
temp = temp.replace(/<span class="url-icon"><img src=".*?" style="width:1em;height:1em;" alt="(.*?)"><\/span>/g, '$1');
// 去掉外部链接的图标
temp = temp.replace(/<span class="url-icon"><img src=".*?"><\/span><\/i>/g, '');
// 去掉多余无意义的标签
temp = temp.replace(/<span class="surl-text">/g, '');
// 最后插入两个空行,让转发的微博排版更加美观一些
temp += '<br><br>';
temp = temp.replace(/<span class=["|']url-icon["|']>.*?网页链接<\/span>/g, '网页链接');
// 表情图标转换为文字
temp = temp.replace(/<span class="url-icon"><img.*?alt="(.*?)".*?><\/span>/g, '$1');
// 去掉全文
temp = temp.replace(/全文<br>/g, '<br>');
// 处理外部链接
temp = temp.replace(/https:\/\/weibo\.cn\/sinaurl\/.*?&u=(http.*?")/g, function(match, p1) {