tags.split(/\s*(?:,|\s+and)\s*/).map { |tag| "<code>#{tag.strip}</code>" }.join(', ') + '.'
end
- def generate_excerpt(max_length = 210)
+ def generate_excerpt(max_length = 950)
return "" if content.blank?
-
stripped_content = ActionController::Base.helpers.strip_tags(content)
- excerpt = stripped_content.split('.').first || stripped_content[0...max_length]
- excerpt = excerpt[0...max_length] if excerpt.length > max_length
+
+ # Split by double line breaks and get first substantive paragraph
+ paragraphs = stripped_content.split(/\r\n\r\n/)
+
+ # Skip the "Dear friends" paragraph and get the next one
+ excerpt = paragraphs.drop(1).first || stripped_content[0...max_length]
+
+ # If we need to trim, find the last complete sentence within max_length
+ if excerpt.length > max_length
+ excerpt = excerpt[0...max_length]
+ # Find the last period that's followed by a space or end of string
+ last_sentence = excerpt.rindex(/\.\s|\.$/)
+ excerpt = excerpt[0..last_sentence] if last_sentence
+ end
+
+ # Clean up the text
excerpt.gsub!("Dear friends,", "")
excerpt.gsub!(/\s+/, ' ')
excerpt.strip