diff --git a/app/models/communication/website/author.rb b/app/models/communication/website/author.rb index 40ae840261d872f5edb1348de55b93c6b8bf43ef..25480be7f5693ede23069e5ecf3c46194dd4b686 100644 --- a/app/models/communication/website/author.rb +++ b/app/models/communication/website/author.rb @@ -52,7 +52,20 @@ class Communication::Website::Author < ApplicationRecord # Override from WithGithubFiles def github_path_generated - "_authors/#{slug}.html" + "auteurs/#{slug}.html" + end + + def github_manifest + super << { + identifier: "collection_item", + generated_path: "_data/authors/#{slug}.yml", + data: -> (github_file) { ApplicationController.render( + template: "admin/communication/website/authors/jekyll_collection", + formats: [:yml], + layout: false, + assigns: { author: self, github_file: github_file } + ) } + } end protected diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index 01063ea022dd66719b8d3465b40bc0c6d8b16706..e029f89a5ed402b3b1f1ef0c68e010d820f80cff 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -81,24 +81,15 @@ class Communication::Website::Category < ApplicationRecord "actualites/#{slug}.html" end - # Override from WithGithubFiles - def to_jekyll(github_file) - ApplicationController.render( - template: "admin/communication/website/categories/jekyll", - layout: false, - assigns: { category: self, github_file: github_file } - ) - end - def github_manifest super << { identifier: "collection_item", - generated_path: "_data/categories/#{slug}.yml", + generated_path: "_data/authors/#{slug}.yml", data: -> (github_file) { ApplicationController.render( - template: "admin/communication/website/categories/jekyll_collection", + template: "admin/communication/website/authors/jekyll_collection", formats: [:yml], layout: false, - assigns: { category: self, github_file: github_file } + assigns: { author: self, github_file: github_file } ) } } end diff --git a/app/models/communication/website/menu.rb b/app/models/communication/website/menu.rb index 5b39c46cad824c2a1a0cb51e809306042d50c973..3214611a33915700fa27e8039146283081f40c6a 100644 --- a/app/models/communication/website/menu.rb +++ b/app/models/communication/website/menu.rb @@ -31,6 +31,8 @@ class Communication::Website::Menu < ApplicationRecord validates :title, :identifier, presence: true validates :identifier, uniqueness: { scope: :communication_website_id } + after_touch :publish_github_files + scope :ordered, -> { order(created_at: :asc) } def to_s diff --git a/app/models/concerns/with_github_files.rb b/app/models/concerns/with_github_files.rb index fb0ad047cf52b9fcb3e969cbe31ab5fc7de8db42..5a6aea780fb94eb018285974e004f5d3d56c8140 100644 --- a/app/models/concerns/with_github_files.rb +++ b/app/models/concerns/with_github_files.rb @@ -6,7 +6,6 @@ module WithGithubFiles after_save :create_github_files after_save_commit :publish_github_files - after_touch :publish_github_files end def force_publish! @@ -41,7 +40,7 @@ module WithGithubFiles def create_github_files list_of_websites.each do |website| github_manifest.each do |manifest_item| - github_files.find_or_create_by(website: website, manifest_identifier: manifest_item[:identifier]) + github_files.where(website: website, manifest_identifier: manifest_item[:identifier]).first_or_create end end end @@ -49,7 +48,7 @@ module WithGithubFiles def publish_github_files list_of_websites.each do |website| github_manifest.each do |manifest_item| - github_file = github_files.find_or_create_by(website: website, manifest_identifier: manifest_item[:identifier]) + github_file = github_files.where(website: website, manifest_identifier: manifest_item[:identifier]).first_or_create github_file.publish end end diff --git a/app/views/admin/communication/website/authors/jekyll.html.erb b/app/views/admin/communication/website/authors/jekyll.html.erb index 7c6661057d42d54adc46a4ce36733aa680eeffaa..2f36fcfbdfd0f56782760acdd94449e612cd12d2 100644 --- a/app/views/admin/communication/website/authors/jekyll.html.erb +++ b/app/views/admin/communication/website/authors/jekyll.html.erb @@ -1,10 +1,15 @@ --- title: "<%= @author.to_s %>" +slug: "<%= @author.slug %>" identifier: "<%= @author.id %>" +permalink: "/auteurs/<%= @author.slug %>" first_name: "<%= @author.first_name %>" last_name: "<%= @author.last_name %>" -slug: "<%= @author.slug %>" biography: > <%= prepare_for_github @author.biography, @author.university %> +pagination: + enabled: true + tag: <%= @author.id %> + permalink: /:num/ --- <%= @github_file.github_frontmatter.content.html_safe %> diff --git a/app/views/admin/communication/website/authors/jekyll_collection.yml.erb b/app/views/admin/communication/website/authors/jekyll_collection.yml.erb new file mode 100644 index 0000000000000000000000000000000000000000..1f1259c0023b423475c0fbe5e2a36a402356e4a7 --- /dev/null +++ b/app/views/admin/communication/website/authors/jekyll_collection.yml.erb @@ -0,0 +1,3 @@ +name: <%= @author.to_s %> +identifier: <%= @author.id %> +link: /auteurs/<%= @author.slug %>