Add a global title length cap. And localisation for Instagram. (#670)

This commit is contained in:
Henry Wang 2018-09-09 17:45:55 +01:00 committed by DIYgod
parent b8bdf9ca58
commit 571636b4a8
4 changed files with 11 additions and 9 deletions

View File

@ -29,6 +29,10 @@ module.exports = async (ctx, next) => {
template = path.resolve(__dirname, '../views/rss.art');
break;
}
// trim title length
ctx.state.data.item.forEach((item) => {
item.title = item.title.length > 80 ? `${item.title.slice(0, 80)}...` : item.title;
});
const data = {
lastBuildDate: new Date().toUTCString(),

View File

@ -45,7 +45,7 @@ module.exports = async (ctx) => {
);
ctx.state.data = {
title: `${name}(@${id}) Instagram`,
title: `${name}(@${id})'s Instagram`,
link: `https://www.instagram.com/${id}/`,
description: $('meta[name="description"]').attr('content'),
item: list.map((item, index) => {
@ -54,11 +54,11 @@ module.exports = async (ctx) => {
let tip = '';
switch (item.__typename) {
case 'GraphVideo':
type = '[视频] ';
tip = '打开原文播放视频: ';
type = '[视频/Video] ';
tip = '打开原文播放视频/click to play the video: ';
break;
case 'GraphSidecar':
type = '[组图] ';
type = '[组图/Carousel] ';
break;
}
let imgTPL = '';
@ -66,7 +66,7 @@ module.exports = async (ctx) => {
imgTPL += `<img referrerpolicy="no-referrer" src="${images[index][i]}"><br>`;
}
return {
title: `${type}${(item.edge_media_to_caption.edges && item.edge_media_to_caption.edges[0] && item.edge_media_to_caption.edges[0].node.text) || '无题'}`,
title: `${type}${(item.edge_media_to_caption.edges && item.edge_media_to_caption.edges[0] && item.edge_media_to_caption.edges[0].node.text) || '无题/Untitled'}`,
description: `${tip}${imgTPL}`,
pubDate: new Date(item.taken_at_timestamp * 1000).toUTCString(),
link: `https://www.instagram.com/p/${item.shortcode}/`,

View File

@ -30,7 +30,7 @@ module.exports = async (ctx) => {
const description = weiboUtils.format(item.mblog);
const title = description.replace(/<img.*?>/g, '[图片]').replace(/<.*?>/g, '');
return {
title: title.length > 24 ? title.slice(0, 24) + '...' : title,
title,
description: description,
pubDate: weiboUtils.getTime(item.mblog.created_at),
link: `https://weibo.com/${uid}/${item.mblog.bid}`,

View File

@ -29,9 +29,7 @@ module.exports = async (ctx) => {
.text()
.replace(/^\s+|\s+$/g, '')
.replace(/\u200B/g, '');
if (wb.title.length > 24) {
wb.title = wb.title.slice(0, 24) + '...';
} else if (wb.title === '') {
if (wb.title === '') {
wb.title = '[图片]';
}
wb.description = titleEle