mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
Small re-organization of CookedPostProcessor workflow
- only 'limit_size!' of oneboxed images once - update post image at the end - move 'enforce_nofollow' in its own method
This commit is contained in:
@ -35,6 +35,8 @@ class CookedPostProcessor
|
|||||||
post_process_images
|
post_process_images
|
||||||
post_process_oneboxes
|
post_process_oneboxes
|
||||||
optimize_urls
|
optimize_urls
|
||||||
|
update_post_image
|
||||||
|
enforce_no_follow
|
||||||
pull_hotlinked_images(bypass_bump)
|
pull_hotlinked_images(bypass_bump)
|
||||||
grant_badges
|
grant_badges
|
||||||
DiscourseEvent.trigger(:post_process_cooked, @doc, @post)
|
DiscourseEvent.trigger(:post_process_cooked, @doc, @post)
|
||||||
@ -312,26 +314,16 @@ class CookedPostProcessor
|
|||||||
@has_oneboxes = true
|
@has_oneboxes = true
|
||||||
Oneboxer.onebox(url, args)
|
Oneboxer.onebox(url, args)
|
||||||
end
|
end
|
||||||
|
|
||||||
update_post_image
|
|
||||||
|
|
||||||
# make sure we grab dimensions for oneboxed images
|
|
||||||
oneboxed_images.each { |img| limit_size!(img) }
|
|
||||||
|
|
||||||
uploads = oneboxed_image_uploads.select(:url, :origin)
|
uploads = oneboxed_image_uploads.select(:url, :origin)
|
||||||
oneboxed_images.each do |img|
|
oneboxed_images.each do |img|
|
||||||
url = img["src"].sub(/^https?:/i, "")
|
url = img["src"].sub(/^https?:/i, "")
|
||||||
upload = uploads.find { |u| u.origin.sub(/^https?:/i, "") == url }
|
upload = uploads.find { |u| u.origin.sub(/^https?:/i, "") == url }
|
||||||
next unless upload.present?
|
img["src"] = upload.url if upload.present?
|
||||||
img["src"] = upload.url
|
|
||||||
# make sure we grab dimensions for oneboxed images
|
|
||||||
limit_size!(img)
|
|
||||||
end
|
|
||||||
|
|
||||||
# respect nofollow admin settings
|
|
||||||
if !@cooking_options[:omit_nofollow] && SiteSetting.add_rel_nofollow_to_user_content
|
|
||||||
PrettyText.add_rel_nofollow_to_user_content(@doc)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# make sure we grab dimensions for oneboxed images
|
||||||
|
oneboxed_images.each { |img| limit_size!(img) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def optimize_urls
|
def optimize_urls
|
||||||
@ -359,6 +351,12 @@ class CookedPostProcessor
|
|||||||
img["src"] = Discourse.store.cdn_url(img["src"]) if use_s3_cdn
|
img["src"] = Discourse.store.cdn_url(img["src"]) if use_s3_cdn
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def enforce_nofollow
|
||||||
|
if !@cooking_options[:omit_nofollow] && SiteSetting.add_rel_nofollow_to_user_content
|
||||||
|
PrettyText.add_rel_nofollow_to_user_content(@doc)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def pull_hotlinked_images(bypass_bump = false)
|
def pull_hotlinked_images(bypass_bump = false)
|
||||||
# is the job enabled?
|
# is the job enabled?
|
||||||
|
Reference in New Issue
Block a user