FIX: use the first image in the first post in the topic as opengraph image

FEATURE: new 'default_opengraph_image_url' setting
This commit is contained in:
Régis Hanol
2015-10-15 11:00:47 +02:00
parent 73e345fe8f
commit 37c5909a31
9 changed files with 29 additions and 25 deletions

View File

@@ -64,7 +64,7 @@ class CookedPostProcessor
convert_to_link!(img)
end
update_topic_image(images)
update_topic_image
end
def extract_images
@@ -80,6 +80,17 @@ class CookedPostProcessor
@doc.css(".quote img")
end
def extract_images_for_topic
# all image with a src attribute
@doc.css("img[src]") -
# minus, emojis
@doc.css("img.emoji") -
# minus, image inside oneboxes
oneboxed_images -
# minus, images inside quotes
@doc.css(".quote img")
end
def oneboxed_images
@doc.css(".onebox-result img, .onebox img")
end
@@ -235,9 +246,9 @@ class CookedPostProcessor
span
end
def update_topic_image(images)
def update_topic_image
if @post.is_first_post?
img = images.first
img = extract_images_for_topic.first
@post.topic.update_column(:image_url, img["src"][0...255]) if img["src"].present?
end
end