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

best featured image

parent 850d4074
No related branches found
No related tags found
No related merge requests found
...@@ -86,6 +86,13 @@ class Communication::Website::Page < ApplicationRecord ...@@ -86,6 +86,13 @@ class Communication::Website::Page < ApplicationRecord
"#{ title }" "#{ title }"
end 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 protected
def slug_unavailable?(slug) def slug_unavailable?(slug)
......
...@@ -2,7 +2,12 @@ module Communication::Website::WithMedia ...@@ -2,7 +2,12 @@ module Communication::Website::WithMedia
extend ActiveSupport::Concern extend ActiveSupport::Concern
def active_storage_blobs 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) university.active_storage_blobs.where(id: blob_ids)
end end
# Can be overwrite to get featured_image from associated objects (ex: parents)
def best_featured_image(fallback: true)
featured_image
end
end end
...@@ -5,8 +5,8 @@ identifier: "<%= @page.id %>" ...@@ -5,8 +5,8 @@ identifier: "<%= @page.id %>"
parent: "<%= @page.parent_id %>" parent: "<%= @page.parent_id %>"
related_category: "<%= @page.related_category_id %>" related_category: "<%= @page.related_category_id %>"
position: <%= @page.position %> position: <%= @page.position %>
<% if @page.featured_image.attached? %> <% if @page.best_featured_image.attached? %>
image: "<%= @page.featured_image.blob.id %>" image: "<%= @page.best_featured_image.blob.id %>"
<% end %> <% end %>
description: > description: >
<%= prepare_for_github @page.description, @page.university %> <%= prepare_for_github @page.description, @page.university %>
......
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