From 8a262ecc2f0718012e7e9b4a61147e8698ffd709 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sat, 23 Apr 2016 22:00:59 +0300 Subject: [PATCH] Limit webpage description length Closes #1113 --- app/js/services.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/js/services.js b/app/js/services.js index 52ccb9cf..bacc47ef 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -1608,12 +1608,15 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) } var siteName = apiWebPage.site_name; - var title = apiWebPage.title || apiWebPage.author || siteName; + var shortTitle = apiWebPage.title || apiWebPage.author || siteName || ''; if (siteName && - title == siteName) { + shortTitle == siteName) { delete apiWebPage.site_name; } - apiWebPage.rTitle = RichTextProcessor.wrapRichText(title, {noLinks: true, noLinebreaks: true}); + if (shortTitle.length > 100) { + shortTitle = shortTitle.substr(0, 80) + '...'; + } + apiWebPage.rTitle = RichTextProcessor.wrapRichText(shortTitle, {noLinks: true, noLinebreaks: true}); var contextHashtag = ''; if (siteName == 'GitHub') { var matches = apiWebPage.url.match(/(https?:\/\/github\.com\/[^\/]+\/[^\/]+)/); @@ -1622,8 +1625,12 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) } } // delete apiWebPage.description; + var shortDescriptionText = (apiWebPage.description || ''); + if (shortDescriptionText.length > 180) { + shortDescriptionText = shortDescriptionText.substr(0, 150).replace(/(\n|\s)+$/, '') + '...'; + } apiWebPage.rDescription = RichTextProcessor.wrapRichText( - apiWebPage.description, { + shortDescriptionText, { contextSite: siteName || 'external', contextHashtag: contextHashtag }