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:
Régis Hanol 2017-10-23 18:15:51 +02:00 committed by GitHub
parent 04ae79896c
commit 80ad32094d

View File

@ -35,6 +35,8 @@ class CookedPostProcessor
post_process_images
post_process_oneboxes
optimize_urls
update_post_image
enforce_no_follow
pull_hotlinked_images(bypass_bump)
grant_badges
DiscourseEvent.trigger(:post_process_cooked, @doc, @post)
@ -312,26 +314,16 @@ class CookedPostProcessor
@has_oneboxes = true
Oneboxer.onebox(url, args)
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)
oneboxed_images.each do |img|
url = img["src"].sub(/^https?:/i, "")
upload = uploads.find { |u| u.origin.sub(/^https?:/i, "") == url }
next unless 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)
img["src"] = upload.url if upload.present?
end
# make sure we grab dimensions for oneboxed images
oneboxed_images.each { |img| limit_size!(img) }
end
def optimize_urls
@ -359,6 +351,12 @@ class CookedPostProcessor
img["src"] = Discourse.store.cdn_url(img["src"]) if use_s3_cdn
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)
# is the job enabled?