diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index f9b54aa15a581f8474ec10f3701989cc0a4c832a..cdb51a35bc4b3fc8ba7aa69f4af3ff4d1c46f88a 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -86,6 +86,13 @@ class Communication::Website::Page < ApplicationRecord "#{ title }" end + def best_featured_image(fallback: true) + return featured_image if featured_image.attached? + best_image = parent&.best_featured_image(fallback: false) + best_image ||= featured_image if fallback + best_image + end + protected def slug_unavailable?(slug) diff --git a/app/models/communication/website/with_media.rb b/app/models/communication/website/with_media.rb index c4aad2b352486abc95685d5ba03e22f6d97d99d5..adc5069cb6ef7b61c345db72e19dd5ab79c6e6ab 100644 --- a/app/models/communication/website/with_media.rb +++ b/app/models/communication/website/with_media.rb @@ -2,7 +2,12 @@ module Communication::Website::WithMedia extend ActiveSupport::Concern def active_storage_blobs - blob_ids = [featured_image&.blob_id, text.embeds.blobs.pluck(:id)].flatten.compact + blob_ids = [best_featured_image&.blob_id, text.embeds.blobs.pluck(:id)].flatten.compact university.active_storage_blobs.where(id: blob_ids) end + + # Can be overwrite to get featured_image from associated objects (ex: parents) + def best_featured_image(fallback: true) + featured_image + end end diff --git a/app/views/admin/communication/website/pages/jekyll.html.erb b/app/views/admin/communication/website/pages/jekyll.html.erb index 279a44f575eb5423b6be3b6af03ced18915c3f74..619921c918876da1cb16cde04dd2f122948fd832 100644 --- a/app/views/admin/communication/website/pages/jekyll.html.erb +++ b/app/views/admin/communication/website/pages/jekyll.html.erb @@ -5,8 +5,8 @@ identifier: "<%= @page.id %>" parent: "<%= @page.parent_id %>" related_category: "<%= @page.related_category_id %>" position: <%= @page.position %> -<% if @page.featured_image.attached? %> -image: "<%= @page.featured_image.blob.id %>" +<% if @page.best_featured_image.attached? %> +image: "<%= @page.best_featured_image.blob.id %>" <% end %> description: > <%= prepare_for_github @page.description, @page.university %>