mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 19:08:10 -05:00
d1d4530efd
- Added PreloadStore support to avoid duplicate requests - preliminary SEO - Support for opengraph/twitter cards
26 lines
469 B
Ruby
26 lines
469 B
Ruby
# Summarize a HTML field into regular text. Used currently
|
|
# for meta tags
|
|
|
|
class Summarize
|
|
include ActionView::Helpers
|
|
|
|
def initialize(text)
|
|
@text = text
|
|
end
|
|
|
|
def self.max_length
|
|
500
|
|
end
|
|
|
|
def summary
|
|
return nil if @text.blank?
|
|
|
|
result = sanitize(@text, tags: [], attributes: [])
|
|
result.gsub!(/\n/, ' ')
|
|
result.strip!
|
|
|
|
return result if result.length <= Summarize.max_length
|
|
"#{result[0..Summarize.max_length]}..."
|
|
end
|
|
|
|
end
|