Don't add ellipsis if not truncated
This commit is contained in:
parent
f222ad1fab
commit
84eaec6e74
@ -23,15 +23,17 @@ module Jekyll
|
|||||||
module SmartTruncate
|
module SmartTruncate
|
||||||
def smart_truncate(input, num_words=100, after='...')
|
def smart_truncate(input, num_words=100, after='...')
|
||||||
doc = Nokogiri::HTML(input)
|
doc = Nokogiri::HTML(input)
|
||||||
smart_truncate_doc(doc, num_words)
|
words = smart_truncate_doc(doc, num_words)
|
||||||
|
|
||||||
body = doc.root.children.first
|
body = doc.root.children.first
|
||||||
|
|
||||||
|
if words >= num_words
|
||||||
if body.children.last.name == 'p' || body.children.last.name == 'div' || body.children.last.name == 'span'
|
if body.children.last.name == 'p' || body.children.last.name == 'div' || body.children.last.name == 'span'
|
||||||
body.children.last.inner_html += after
|
body.children.last.inner_html += after
|
||||||
else
|
else
|
||||||
body << after
|
body << after
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return body.inner_html
|
return body.inner_html
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user