correct hack and move to oneboxer
This commit is contained in:
parent
5a297fe31c
commit
57870b970d
|
@ -11,7 +11,7 @@ class PostAnalyzer
|
||||||
def cook(*args)
|
def cook(*args)
|
||||||
cooked = PrettyText.cook(*args)
|
cooked = PrettyText.cook(*args)
|
||||||
|
|
||||||
result = Oneboxer.apply(cooked) do |url, _|
|
result = Oneboxer.apply(cooked, topic_id: @topic_id) do |url, _|
|
||||||
Oneboxer.invalidate(url) if args.last[:invalidate_oneboxes]
|
Oneboxer.invalidate(url) if args.last[:invalidate_oneboxes]
|
||||||
Oneboxer.cached_onebox url
|
Oneboxer.cached_onebox url
|
||||||
end
|
end
|
||||||
|
|
|
@ -245,19 +245,7 @@ class CookedPostProcessor
|
||||||
}
|
}
|
||||||
|
|
||||||
# apply oneboxes
|
# apply oneboxes
|
||||||
Oneboxer.apply(@doc) { |url|
|
Oneboxer.apply(@doc, topic_id: @post.topic_id) { |url|
|
||||||
|
|
||||||
# hack urls to create proper expansions
|
|
||||||
if url =~ Regexp.new("^#{Discourse.base_url.gsub(".","\\.")}.*$", true)
|
|
||||||
uri = URI.parse(url) rescue nil
|
|
||||||
if uri && uri.path
|
|
||||||
route = Rails.application.routes.recognize_path(uri.path) rescue nil
|
|
||||||
if route && route[:controller] == 'topics'
|
|
||||||
url += (url =~ /\?/ ? "&" : "?") + "&source_topic_id=#{@post.topic_id}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Oneboxer.onebox(url, args)
|
Oneboxer.onebox(url, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,12 +76,30 @@ module Oneboxer
|
||||||
doc
|
doc
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.apply(string_or_doc)
|
def self.append_source_topic_id(url, topic_id)
|
||||||
|
# hack urls to create proper expansions
|
||||||
|
if url =~ Regexp.new("^#{Discourse.base_url.gsub(".","\\.")}.*$", true)
|
||||||
|
uri = URI.parse(url) rescue nil
|
||||||
|
if uri && uri.path
|
||||||
|
route = Rails.application.routes.recognize_path(uri.path) rescue nil
|
||||||
|
if route && route[:controller] == 'topics'
|
||||||
|
url += (url =~ /\?/ ? "&" : "?") + "source_topic_id=#{topic_id}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
url
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.apply(string_or_doc, args=nil)
|
||||||
doc = string_or_doc
|
doc = string_or_doc
|
||||||
doc = Nokogiri::HTML::fragment(doc) if doc.is_a?(String)
|
doc = Nokogiri::HTML::fragment(doc) if doc.is_a?(String)
|
||||||
changed = false
|
changed = false
|
||||||
|
|
||||||
Oneboxer.each_onebox_link(doc) do |url, element|
|
Oneboxer.each_onebox_link(doc) do |url, element|
|
||||||
|
|
||||||
|
if args && args[:topic_id]
|
||||||
|
url = append_source_topic_id(url, args[:topic_id])
|
||||||
|
end
|
||||||
onebox, _preview = yield(url,element)
|
onebox, _preview = yield(url,element)
|
||||||
if onebox
|
if onebox
|
||||||
parsed_onebox = Nokogiri::HTML::fragment(onebox)
|
parsed_onebox = Nokogiri::HTML::fragment(onebox)
|
||||||
|
|
Loading…
Reference in New Issue