Simple format excerpts in activity

This commit is contained in:
Jason Zimdars
2025-05-28 17:18:20 -05:00
parent 4c88c192f9
commit a69dbdafe1
2 changed files with 13 additions and 1 deletions
+12
View File
@@ -0,0 +1,12 @@
module ExcerptHelper
def format_excerpt(content, length: 200)
return "" if content.blank?
text = content.to_plain_text
text = text.gsub(/^>\s*(.*)$/m, '> \1')
text = text.gsub(/^[-*]\s*(.*)$/m, '• \1')
text = text.gsub(/^\d+\.\s*(.*)$/m) { |m| m }
text = text.gsub(/\s+/, " ").strip
text.truncate(length)
end
end
+1 -1
View File
@@ -1,5 +1,5 @@
<%= render "events/event/layout", card: event.eventable.card, event: event do %>
<span class="txt-break overflow-line-clamp txt-tight-lines">
<%= strip_tags(event&.eventable.body.to_s).truncate(200) -%>
<%= format_excerpt(event&.eventable.body, length: 200) -%>
</span>
<% end %>