diff options
-rw-r--r-- | app/helpers/page_layout_helper.rb | 4 | ||||
-rw-r--r-- | spec/helpers/page_layout_helper_spec.rb | 13 |
2 files changed, 15 insertions, 2 deletions
diff --git a/app/helpers/page_layout_helper.rb b/app/helpers/page_layout_helper.rb index c4eb09bea2b..4f1276f93ec 100644 --- a/app/helpers/page_layout_helper.rb +++ b/app/helpers/page_layout_helper.rb @@ -30,9 +30,9 @@ module PageLayoutHelper @page_description ||= page_description_default if description.present? - @page_description = description + @page_description = description.squish else - sanitize(@page_description.squish, tags: []) + sanitize(@page_description, tags: []).truncate_words(30) end end diff --git a/spec/helpers/page_layout_helper_spec.rb b/spec/helpers/page_layout_helper_spec.rb index 5d95beac908..530e9bab343 100644 --- a/spec/helpers/page_layout_helper_spec.rb +++ b/spec/helpers/page_layout_helper_spec.rb @@ -22,6 +22,19 @@ describe PageLayoutHelper do expect(helper.page_description).to eq 'Foo Bar Baz' end + it 'truncates' do + helper.page_description <<-LOREM.strip_heredoc + Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo + ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis + dis parturient montes, nascetur ridiculus mus. Donec quam felis, + ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa + quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, + arcu. + LOREM + + expect(helper.page_description).to end_with 'quam felis,...' + end + it 'sanitizes all HTML' do helper.page_description("<b>Bold</b> <h1>Header</h1>") |