mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 06:41:25 +08:00
FEATURE: Show more context in Discourse topic oneboxes
Currently when generating a onebox for Discourse topics, some important context is missing such as categories and tags. This patch addresses this issue by introducing a new onebox engine dedicated to display this information when available. Indeed to get this new information, categories and tags are exposed in the topic metadata as opengraph tags.
This commit is contained in:

committed by
Loïc Guitaut

parent
d2e9ea6193
commit
14d97f9cf1
@ -4,19 +4,11 @@ module Onebox
|
||||
class Normalizer
|
||||
attr_reader :data
|
||||
|
||||
def get(attr, length = nil, sanitize = true)
|
||||
return nil if Onebox::Helpers.blank?(data)
|
||||
|
||||
def get(attr, *args)
|
||||
value = data[attr]
|
||||
|
||||
return nil if Onebox::Helpers.blank?(value)
|
||||
|
||||
value = html_entities.decode(value)
|
||||
value = Sanitize.fragment(value) if sanitize
|
||||
value.strip!
|
||||
value = Onebox::Helpers.truncate(value, length) unless length.nil?
|
||||
|
||||
value
|
||||
return if value.blank?
|
||||
return value.map { |v| sanitize_value(v, *args) } if value.is_a?(Array)
|
||||
sanitize_value(value, *args)
|
||||
end
|
||||
|
||||
def method_missing(attr, *args, &block)
|
||||
@ -48,5 +40,13 @@ module Onebox
|
||||
def html_entities
|
||||
@html_entities ||= HTMLEntities.new
|
||||
end
|
||||
|
||||
def sanitize_value(value, length = nil, sanitize = true)
|
||||
value = html_entities.decode(value)
|
||||
value = Sanitize.fragment(value) if sanitize
|
||||
value.strip!
|
||||
value = Onebox::Helpers.truncate(value, length) if length
|
||||
value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user