From fd020d7e9a6eef7f7e29d24b1a5617573014cb96 Mon Sep 17 00:00:00 2001
From: pabois <pierreandre.boissinot@noesya.coop>
Date: Mon, 12 Dec 2022 12:32:00 +0100
Subject: [PATCH] add ancestors slugs to post references

---
 app/models/communication/website/category.rb                 | 4 ++++
 app/views/admin/communication/websites/posts/static.html.erb | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb
index a805bbd3b..a00ecbed6 100644
--- a/app/models/communication/website/category.rb
+++ b/app/models/communication/website/category.rb
@@ -107,6 +107,10 @@ class Communication::Website::Category < ApplicationRecord
     self.class.unscoped.where(parent: parent, university: university, website: website).where.not(id: id)
   end
 
+  def slug_with_ancestors_slugs
+    (ancestors.map(&:slug) << slug).join('/')
+  end
+
   protected
 
   def last_ordered_element
diff --git a/app/views/admin/communication/websites/posts/static.html.erb b/app/views/admin/communication/websites/posts/static.html.erb
index 493680a8a..21a4f9d17 100644
--- a/app/views/admin/communication/websites/posts/static.html.erb
+++ b/app/views/admin/communication/websites/posts/static.html.erb
@@ -12,7 +12,7 @@ authors:
 <% if @about.categories.any? %>
 categories:
   <% @about.categories.each do |category| %>
-  - "<%= category.slug %>"
+  - "<%= category.slug_with_ancestors_slugs %>"
   <% end %>
 <% end %>
 <%= render 'admin/communication/unsplash/static' %>
-- 
GitLab