From 84eaec6e74d6a1ac2436a039c9672a3c0c4fa37b Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Mon, 19 Feb 2018 19:08:17 +1100 Subject: [PATCH] Don't add ellipsis if not truncated --- smart_truncate.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/smart_truncate.rb b/smart_truncate.rb index 5b90852..fd569ae 100644 --- a/smart_truncate.rb +++ b/smart_truncate.rb @@ -23,14 +23,16 @@ module Jekyll module SmartTruncate def smart_truncate(input, num_words=100, after='...') doc = Nokogiri::HTML(input) - smart_truncate_doc(doc, num_words) + words = smart_truncate_doc(doc, num_words) body = doc.root.children.first - if body.children.last.name == 'p' || body.children.last.name == 'div' || body.children.last.name == 'span' - body.children.last.inner_html += after - else - body << after + if words >= num_words + if body.children.last.name == 'p' || body.children.last.name == 'div' || body.children.last.name == 'span' + body.children.last.inner_html += after + else + body << after + end end return body.inner_html