From 571636b4a8b4ca8d730ecb50652fb901729764cd Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Sun, 9 Sep 2018 17:45:55 +0100 Subject: [PATCH] Add a global title length cap. And localisation for Instagram. (#670) --- middleware/template.js | 4 ++++ routes/instagram/user.js | 10 +++++----- routes/weibo/user.js | 2 +- routes/weibo/user2.js | 4 +--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/middleware/template.js b/middleware/template.js index 53fe43038..7fa9b64a0 100644 --- a/middleware/template.js +++ b/middleware/template.js @@ -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(), diff --git a/routes/instagram/user.js b/routes/instagram/user.js index 2f9c6dc85..b577d88a0 100644 --- a/routes/instagram/user.js +++ b/routes/instagram/user.js @@ -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 += `
`; } 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}/`, diff --git a/routes/weibo/user.js b/routes/weibo/user.js index d7d49cdb4..41bcb6d7f 100644 --- a/routes/weibo/user.js +++ b/routes/weibo/user.js @@ -30,7 +30,7 @@ module.exports = async (ctx) => { const description = weiboUtils.format(item.mblog); const title = description.replace(//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}`, diff --git a/routes/weibo/user2.js b/routes/weibo/user2.js index 7ec5aae33..02d8b174a 100644 --- a/routes/weibo/user2.js +++ b/routes/weibo/user2.js @@ -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