From 510ea35deb222d2448b0acc551981fa924d60af6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Fri, 17 Dec 2021 15:27:35 +0100
Subject: [PATCH] image jekyll program

---
 app/models/education/program.rb                    | 7 +++++++
 app/views/admin/education/programs/jekyll.html.erb | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/app/models/education/program.rb b/app/models/education/program.rb
index a8faccd0c..6ad5acac4 100644
--- a/app/models/education/program.rb
+++ b/app/models/education/program.rb
@@ -85,6 +85,13 @@ class Education::Program < ApplicationRecord
     description.blank? ? parent&.best_description : description
   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
+
   # Override from WithGithubFiles
   def github_path_generated
     "_programs/#{path}/index.html".gsub(/\/+/, '/')
diff --git a/app/views/admin/education/programs/jekyll.html.erb b/app/views/admin/education/programs/jekyll.html.erb
index befd6e8be..6a1303798 100644
--- a/app/views/admin/education/programs/jekyll.html.erb
+++ b/app/views/admin/education/programs/jekyll.html.erb
@@ -7,6 +7,9 @@ continuing: <%= @program.continuing %>
 level: <%= @program.level %>
 ects: <%= @program.ects %>
 position: <%= @program.position %>
+<% if @program.best_featured_image.attached? %>
+image: "<%= @program.best_featured_image.blob.id %>"
+<% end %>
 <% if @program.teachers.any? %>
 teachers:
   <% @program.teachers.each do |teacher| %>
-- 
GitLab