Skip to content
Snippets Groups Projects
Commit a6ca7d6b authored by Arnaud Levy's avatar Arnaud Levy
Browse files

fixes

parent 8a80baf2
No related branches found
No related tags found
No related merge requests found
......@@ -63,7 +63,7 @@ module Admin::ApplicationHelper
def prepare_for_github(html)
text = html.to_s
text = sanitize text,
tags: %w(table a figure img figcaption i em b strong h2 h3 h4 h5 h6 blockquote),
tags: %w(table a figure img figcaption i em b strong p h2 h3 h4 h5 h6 blockquote),
attributes: %w(href alt title target rel src srcset width height)
text.gsub! "\r", ''
text.gsub! "\n", ' '
......
......@@ -91,9 +91,28 @@ class Communication::Website::Imported::Post < ApplicationRecord
post.updated_at = updated_at
post.published_at = published_at if published_at
post.published = true
if featured_medium.nil?
# Use first image in text as featured medium
end
post.save
download_first_image_as_featured_image if featured_medium.nil?
end
# Please refactor me i'm ugly
def download_first_image_as_featured_image
doc = Nokogiri::HTML(post.text.to_s)
images = doc.css('img')
if images.any?
url = images.first.attr('src')
uri = URI(url)
filename = File.basename url
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
begin
post.featured_image.attach(io: StringIO.new(response.body), filename: filename, content_type: 'image/jpeg')
ensure
tempfile.close!
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment