Skip to content
Snippets Groups Projects
Unverified Commit 220e9d49 authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

without conern

parent 7f024ef4
No related branches found
No related tags found
No related merge requests found
......@@ -36,7 +36,6 @@
# fk_rails_... (website_id => communication_website_imported_websites.id)
#
class Communication::Website::Imported::Page < ApplicationRecord
include Communication::Website::Imported::WithFeaturedImage
include Communication::Website::Imported::WithRichText
belongs_to :university
......@@ -94,9 +93,25 @@ class Communication::Website::Imported::Page < ApplicationRecord
page.published = true
page.save
if featured_medium.present?
download_featured_medium_file_as_featured_image(page)
featured_medium.load_remote_file! unless featured_medium.file.attached?
page.featured_image.attach(
io: URI.open(featured_medium.file.blob.url),
filename: featured_medium.file.blob.filename,
content_type: featured_medium.file.blob.content_type
)
else
download_first_image_in_text_as_featured_image(page)
fragment = Nokogiri::HTML.fragment(page.text.to_s)
image = fragment.css('img').first
if image.present?
begin
url = image.attr('src')
download_service = DownloadService.download(url)
page.featured_image.attach(download_service.attachable_data)
image.remove
page.update(text: fragment.to_html)
rescue
end
end
end
page.update(text: rich_text_with_attachments(page.text.to_s))
end
......
......@@ -35,7 +35,6 @@
# fk_rails_... (website_id => communication_website_imported_websites.id)
#
class Communication::Website::Imported::Post < ApplicationRecord
include Communication::Website::Imported::WithFeaturedImage
include Communication::Website::Imported::WithRichText
belongs_to :university
......@@ -96,9 +95,25 @@ class Communication::Website::Imported::Post < ApplicationRecord
post.published = true
post.save
if featured_medium.present?
download_featured_medium_file_as_featured_image(post)
featured_medium.load_remote_file! unless featured_medium.file.attached?
post.featured_image.attach(
io: URI.open(featured_medium.file.blob.url),
filename: featured_medium.file.blob.filename,
content_type: featured_medium.file.blob.content_type
)
else
download_first_image_in_text_as_featured_image(post)
fragment = Nokogiri::HTML.fragment(post.text.to_s)
image = fragment.css('img').first
if image.present?
begin
url = image.attr('src')
download_service = DownloadService.download(url)
post.featured_image.attach(download_service.attachable_data)
image.remove
post.update(text: fragment.to_html)
rescue
end
end
end
post.update(text: rich_text_with_attachments(post.text.to_s))
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