]> gitweb.mndrdr.org Git - arelpe.git/commitdiff
fixed an edge case where the rss would fail
authorAidan Cornelius-Bell <[email protected]>
Sun, 15 Sep 2024 01:47:52 +0000 (11:17 +0930)
committerAidan Cornelius-Bell <[email protected]>
Sun, 15 Sep 2024 01:47:52 +0000 (11:17 +0930)
app/models/post.rb

index 64e613ef98c4c078613995ba23cc58e38a8b1d7c..d39b61c0d09702f565979ed160fad1d42ae1c08a 100644 (file)
@@ -47,10 +47,10 @@ class Post < ApplicationRecord
 
   def generate_excerpt(max_length = 180)
     stripped_content = ActionController::Base.helpers.strip_tags(content)
-    excerpt = stripped_content.split('.').first || stripped_content[0...max_length]
-    excerpt.gsub!("Dear friends,", "")
-    excerpt.gsub!(/\s+/, ' ')
-    excerpt.strip
+    excerpt = stripped_content.split('.').first if stripped_content.present? || stripped_content[0...max_length] if stripped_content.present?
+    excerpt.gsub!("Dear friends,", "") if excerpt.present?
+    excerpt.gsub!(/\s+/, ' ') if excerpt.present?
+    excerpt.strip  if excerpt.present?
   end
 
   private