From 1d5bec7beb5fbc120cc0bb3e1669e06b500aa794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com> Date: Thu, 15 Dec 2022 16:39:54 +0100 Subject: [PATCH] git path content prefix --- app/models/communication/website.rb | 2 +- app/models/communication/website/category.rb | 2 +- app/models/communication/website/page/with_path.rb | 10 +++++++--- app/models/communication/website/post.rb | 2 +- app/models/concerns/with_git.rb | 8 ++++++++ app/models/education/diploma.rb | 2 +- app/models/education/program.rb | 2 +- app/models/research/journal/paper.rb | 2 +- app/models/research/journal/volume.rb | 2 +- app/models/university/organization.rb | 2 +- app/models/university/person.rb | 2 +- app/models/university/person/administrator.rb | 2 +- app/models/university/person/author.rb | 2 +- app/models/university/person/researcher.rb | 2 +- app/models/university/person/teacher.rb | 2 +- 15 files changed, 28 insertions(+), 16 deletions(-) diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 1b53a75e6..72f5ddb8b 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -30,7 +30,7 @@ # fk_rails_bb6a496c08 (university_id => universities.id) # class Communication::Website < ApplicationRecord - self.filter_attributes += [ :access_token ] + self.filter_attributes += [:access_token] include WithUniversity include WithAbouts diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index 3f378dcb0..1d3d87c76 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -81,7 +81,7 @@ class Communication::Website::Category < ApplicationRecord end def git_path(website) - "content/categories/#{slug_with_ancestors_slugs}/_index.html" + "#{git_path_content_prefix(website)}categories/#{slug_with_ancestors_slugs}/_index.html" end def template_static diff --git a/app/models/communication/website/page/with_path.rb b/app/models/communication/website/page/with_path.rb index 636653db2..9ff256b12 100644 --- a/app/models/communication/website/page/with_path.rb +++ b/app/models/communication/website/page/with_path.rb @@ -33,13 +33,17 @@ module Communication::Website::Page::WithPath def git_path(website) return unless website.id == communication_website_id && published + + path = git_path_content_prefix(website) if kind_home? - "content/_index.html" + path += "_index.html" elsif has_special_git_path? - "content/#{kind.split('_').last}/_index.html" + path += "#{kind.split('_').last}/_index.html" else - "content/pages/#{path}/_index.html" + path += "pages/#{path_without_language}/_index.html" end + + path end def url diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 72f74c321..5704cc4b8 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -108,7 +108,7 @@ class Communication::Website::Post < ApplicationRecord end def git_path(website) - "content/posts/#{static_path}.html" if website.id == communication_website_id && published && published_at + "#{git_path_content_prefix(website)}posts/#{static_path}.html" if website.id == communication_website_id && published && published_at end def static_path diff --git a/app/models/concerns/with_git.rb b/app/models/concerns/with_git.rb index 2da1884f0..2c07b0b2d 100644 --- a/app/models/concerns/with_git.rb +++ b/app/models/concerns/with_git.rb @@ -12,6 +12,14 @@ module WithGit raise NotImplementedError end + def git_path_content_prefix(website) + # Handle legacy language-less websites + # TODO: Right now, we use the language of the website. It HAS TO get the language from the object including this concern. + path = "content/" + path += "#{website.languages.first.iso_code}/" if website.languages.any? + path + end + def before_git_sync # Can be override to force some process before sync # ex: ActiveStorage Blob analyze diff --git a/app/models/education/diploma.rb b/app/models/education/diploma.rb index 00cd553a0..614f4afd8 100644 --- a/app/models/education/diploma.rb +++ b/app/models/education/diploma.rb @@ -66,7 +66,7 @@ class Education::Diploma < ApplicationRecord end def git_path(website) - "content/diplomas/#{slug}/_index.html" if for_website?(website) + "#{git_path_content_prefix(website)}diplomas/#{slug}/_index.html" if for_website?(website) end def git_dependencies(website) diff --git a/app/models/education/program.rb b/app/models/education/program.rb index 9ffd591ce..271faf60c 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -133,7 +133,7 @@ class Education::Program < ApplicationRecord end def git_path(website) - "content/programs/#{path}/_index.html" if for_website?(website) + "#{git_path_content_prefix(website)}programs/#{path}/_index.html" if for_website?(website) end def path_in_website(website) diff --git a/app/models/research/journal/paper.rb b/app/models/research/journal/paper.rb index 36cb94a1b..d257f16a5 100644 --- a/app/models/research/journal/paper.rb +++ b/app/models/research/journal/paper.rb @@ -62,7 +62,7 @@ class Research::Journal::Paper < ApplicationRecord scope :ordered, -> { order(published_at: :desc, created_at: :desc) } def git_path(website) - "content/papers/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" if (volume.nil? || volume.published_at) && published_at + "#{git_path_content_prefix(website)}papers/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" if (volume.nil? || volume.published_at) && published_at end def template_static diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb index 52fd676b4..2b14ba3bf 100644 --- a/app/models/research/journal/volume.rb +++ b/app/models/research/journal/volume.rb @@ -53,7 +53,7 @@ class Research::Journal::Volume < ApplicationRecord end def git_path(website) - "content/volumes/#{published_at.year}/#{slug}/_index.html" if published_at + "#{git_path_content_prefix(website)}volumes/#{published_at.year}/#{slug}/_index.html" if published_at end def template_static diff --git a/app/models/university/organization.rb b/app/models/university/organization.rb index b7e6cd4ae..31c57551e 100644 --- a/app/models/university/organization.rb +++ b/app/models/university/organization.rb @@ -108,7 +108,7 @@ class University::Organization < ApplicationRecord end def git_path(website) - "content/organizations/#{slug}.html" if for_website?(website) + "#{git_path_content_prefix(website)}organizations/#{slug}.html" if for_website?(website) end def to_s diff --git a/app/models/university/person.rb b/app/models/university/person.rb index 1e7716b6a..39479bef3 100644 --- a/app/models/university/person.rb +++ b/app/models/university/person.rb @@ -177,7 +177,7 @@ class University::Person < ApplicationRecord end def git_path(website) - "content/persons/#{slug}.html" if for_website?(website) + "#{git_path_content_prefix(website)}persons/#{slug}.html" if for_website?(website) end def git_dependencies(website) diff --git a/app/models/university/person/administrator.rb b/app/models/university/person/administrator.rb index cc72eecb8..d90758a24 100644 --- a/app/models/university/person/administrator.rb +++ b/app/models/university/person/administrator.rb @@ -51,7 +51,7 @@ class University::Person::Administrator < University::Person end def git_path(website) - "content/administrators/#{slug}/_index.html" if for_website?(website) + "#{git_path_content_prefix(website)}administrators/#{slug}/_index.html" if for_website?(website) end def template_static diff --git a/app/models/university/person/author.rb b/app/models/university/person/author.rb index 08ad2f90c..a41fe14bf 100644 --- a/app/models/university/person/author.rb +++ b/app/models/university/person/author.rb @@ -51,7 +51,7 @@ class University::Person::Author < University::Person end def git_path(website) - "content/authors/#{slug}/_index.html" if for_website?(website) + "#{git_path_content_prefix(website)}authors/#{slug}/_index.html" if for_website?(website) end def template_static diff --git a/app/models/university/person/researcher.rb b/app/models/university/person/researcher.rb index 254d0ce1f..2a54ba57d 100644 --- a/app/models/university/person/researcher.rb +++ b/app/models/university/person/researcher.rb @@ -51,7 +51,7 @@ class University::Person::Researcher < University::Person end def git_path(website) - "content/researchers/#{slug}/_index.html" if for_website?(website) + "#{git_path_content_prefix(website)}researchers/#{slug}/_index.html" if for_website?(website) end def template_static diff --git a/app/models/university/person/teacher.rb b/app/models/university/person/teacher.rb index 83303c45c..7d7476461 100644 --- a/app/models/university/person/teacher.rb +++ b/app/models/university/person/teacher.rb @@ -52,7 +52,7 @@ class University::Person::Teacher < University::Person end def git_path(website) - "content/teachers/#{slug}/_index.html" if for_website?(website) + "#{git_path_content_prefix(website)}teachers/#{slug}/_index.html" if for_website?(website) end def template_static -- GitLab