From 80ad32094d4e657ca119946058ef6d7843e68028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 23 Oct 2017 18:15:51 +0200 Subject: [PATCH] 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 --- lib/cooked_post_processor.rb | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index 278a570464e..2aacbe3fb4f 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -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?