Skip to content

Commit

Permalink
move image validation to extraction filter
Browse files Browse the repository at this point in the history
  • Loading branch information
angusmcleod committed Aug 5, 2018
1 parent bf31dd2 commit 7c5130d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/cooked_post_processor_edits.rb
Expand Up @@ -4,7 +4,9 @@ def extract_post_image
(extract_images_for_post -
@doc.css("img.thumbnail") -
@doc.css("img.site-icon") -
@doc.css("img.avatar")).first
@doc.css("img.avatar"))
.select { |img| validate_image_for_previews(img) }
.first
end

def determine_image_size(img)
Expand All @@ -13,15 +15,13 @@ def determine_image_size(img)
get_size(img["src"])
end

def valiate_image_for_previews(img)
def validate_image_for_previews(img)
w, h = determine_image_size(img)
w >= 100 && h >= 100
end

def update_post_image
extracted = extract_post_image

img = extracted if valiate_image_for_previews(extracted)
img = extract_post_image

if @has_oneboxes
cooked = PrettyText.cook(@post.raw)
Expand All @@ -47,7 +47,7 @@ def update_post_image
class_str.include?('site-icon') || class_str.include?('avatar')
end

if prior_oneboxes.any? && valiate_image_for_previews(prior_oneboxes.first)
if prior_oneboxes.any? && validate_image_for_previews(prior_oneboxes.first)
img = prior_oneboxes.first
end
end
Expand Down

0 comments on commit 7c5130d

Please sign in to comment.