From aa16d6832401a75434520299dfe1ae2b2668a478 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Fri, 22 Oct 2021 13:42:24 +0200
Subject: [PATCH] featured image

---
 app/views/admin/communication/website/posts/_form.html.erb  | 1 +
 app/views/admin/communication/website/posts/_list.html.erb  | 3 +++
 app/views/admin/communication/website/posts/jekyll.html.erb | 3 +++
 app/views/admin/communication/website/posts/show.html.erb   | 6 ++++++
 4 files changed, 13 insertions(+)

diff --git a/app/views/admin/communication/website/posts/_form.html.erb b/app/views/admin/communication/website/posts/_form.html.erb
index 3bf62603e..f029d406f 100644
--- a/app/views/admin/communication/website/posts/_form.html.erb
+++ b/app/views/admin/communication/website/posts/_form.html.erb
@@ -20,6 +20,7 @@
         <div class="card-body">
           <%= f.input :published %>
           <%= f.input :published_at, html5: true %>
+          <%= f.input :featured_image %>
         </div>
       </div>
     </div>
diff --git a/app/views/admin/communication/website/posts/_list.html.erb b/app/views/admin/communication/website/posts/_list.html.erb
index 7f6971c59..2d89d1a61 100644
--- a/app/views/admin/communication/website/posts/_list.html.erb
+++ b/app/views/admin/communication/website/posts/_list.html.erb
@@ -2,6 +2,7 @@
   <thead>
     <tr>
       <th><%= Communication::Website::Post.human_attribute_name('title') %></th>
+      <th><%= Communication::Website::Post.human_attribute_name('featured_image') %></th>
       <th><%= Communication::Website::Post.human_attribute_name('published_at') %></th>
       <th></th>
     </tr>
@@ -10,6 +11,8 @@
     <% posts.each do |post| %>
       <tr>
         <td><%= link_to post, admin_communication_website_post_path(website_id: post.website.id, id: post.id) %></td>
+        <td><%= image_tag post.featured_image.variant(resize: 'x100'),
+                          height: 50 if post.featured_image.attached? %></td>
         <td><%= l post.published_at, format: :long if post.published_at %></td>
         <td class="text-end">
           <div class="btn-group" role="group">
diff --git a/app/views/admin/communication/website/posts/jekyll.html.erb b/app/views/admin/communication/website/posts/jekyll.html.erb
index 960aa421e..36e588c2f 100644
--- a/app/views/admin/communication/website/posts/jekyll.html.erb
+++ b/app/views/admin/communication/website/posts/jekyll.html.erb
@@ -2,6 +2,9 @@
 title: "<%= @post.title %>"
 date: <%= @post.published_at %> UTC
 slug: "<%= @post.slug %>"
+<% if @post.featured_image.attached? %>
+image: "<%= url_for @post.featured_image %>"
+<% end %>
 description: >
   <%= prepare_for_github @post.description %>
 text: >
diff --git a/app/views/admin/communication/website/posts/show.html.erb b/app/views/admin/communication/website/posts/show.html.erb
index 1fd65d4be..9f7ff79df 100644
--- a/app/views/admin/communication/website/posts/show.html.erb
+++ b/app/views/admin/communication/website/posts/show.html.erb
@@ -43,6 +43,12 @@
               <td><a href="<%= @post.imported_post.url %>" target="_blank">Original URL</a></td>
             </tr>
           <% end %>
+          <% if @post.featured_image.attached? %>
+            <tr>
+              <td><%= t('communication.website.imported.featured_image') %></td>
+              <td><%= image_tag @post.featured_image.variant(resize: '400'), class: 'img-responsive' %></td>
+            </tr>
+            <% end %>
         </tbody>
       </table>
     </div>
-- 
GitLab