mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 20:21:25 +08:00
User Profile enhancements:
- Added PreloadStore support to avoid duplicate requests - preliminary SEO - Support for opengraph/twitter cards
This commit is contained in:
26
lib/summarize.rb
Normal file
26
lib/summarize.rb
Normal file
@ -0,0 +1,26 @@
|
||||
# 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
|
Reference in New Issue
Block a user