mirror of
https://github.com/openstreetmap/openstreetmap-website.git
synced 2025-07-22 01:22:54 +00:00
Truncate rich text descriptions at word boundaries if not too short
This commit is contained in:
@ -6,6 +6,7 @@ module RichText
|
||||
].freeze
|
||||
|
||||
DESCRIPTION_MAX_LENGTH = 500
|
||||
DESCRIPTION_WORD_BREAK_THRESHOLD_LENGTH = 450
|
||||
|
||||
def self.new(format, text)
|
||||
case format
|
||||
@ -238,7 +239,13 @@ module RichText
|
||||
|
||||
return nil if text.blank?
|
||||
|
||||
text.truncate(DESCRIPTION_MAX_LENGTH)
|
||||
text_truncated_to_word_break = text.truncate(DESCRIPTION_MAX_LENGTH, :separator => " ")
|
||||
|
||||
if text_truncated_to_word_break.length >= DESCRIPTION_WORD_BREAK_THRESHOLD_LENGTH
|
||||
text_truncated_to_word_break
|
||||
else
|
||||
text.truncate(DESCRIPTION_MAX_LENGTH)
|
||||
end
|
||||
end
|
||||
|
||||
def image?(element)
|
||||
|
Reference in New Issue
Block a user