diff --git a/app/helpers/admin/application_helper.rb b/app/helpers/admin/application_helper.rb index c141708a03cb2375995409621da9ad6d14fd159e..1924e94f45cda33c26b6f8c080351697c95b0a7b 100644 --- a/app/helpers/admin/application_helper.rb +++ b/app/helpers/admin/application_helper.rb @@ -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", ' ' diff --git a/app/models/communication/website/imported/post.rb b/app/models/communication/website/imported/post.rb index 07d13e9214817b472c5ddccefecad4827a964af9..e199cce4ad4b066cdee7c59478364f0417d53451 100644 --- a/app/models/communication/website/imported/post.rb +++ b/app/models/communication/website/imported/post.rb @@ -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 diff --git a/config/locales/fr.yml b/config/locales/fr.yml index d95941577ad7f1932f70ce62c1aa07eb14d037c1..b34e7ed94917978403c2992c53e18273f70f1a20 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -120,3 +120,10 @@ fr: terms_of_service_url: https://osuny.org/conditions-d-utilisation true: Oui validate: Valider + views: + pagination: + first: "« Premier" + last: "Dernier »" + previous: "‹ Précédent" + next: "Suivant ›" + truncate: "…"