From 2d89662c7ad511c449b65facf2c696d6c8a8e5ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com> Date: Thu, 9 Dec 2021 14:49:57 +0100 Subject: [PATCH] category has 2 github files per website --- app/models/communication/website/category.rb | 24 ++++++++++++++++++- .../communication/website/github_file.rb | 6 ++--- app/models/concerns/with_github_files.rb | 3 ++- app/services/github.rb | 1 + .../website/categories/jekyll.html.erb | 5 ++++ .../categories/jekyll_collection.yml.erb | 5 ++++ 6 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 app/views/admin/communication/website/categories/jekyll_collection.yml.erb diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index 97d2e66ec..01063ea02 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -78,7 +78,29 @@ class Communication::Website::Category < ApplicationRecord # Override from WithGithubFiles def github_path_generated - "_categories/#{slug}.html" + "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", + data: -> (github_file) { ApplicationController.render( + template: "admin/communication/website/categories/jekyll_collection", + formats: [:yml], + layout: false, + assigns: { category: self, github_file: github_file } + ) } + } end protected diff --git a/app/models/communication/website/github_file.rb b/app/models/communication/website/github_file.rb index ea3739206..9fc025e09 100644 --- a/app/models/communication/website/github_file.rb +++ b/app/models/communication/website/github_file.rb @@ -30,7 +30,7 @@ class Communication::Website::GithubFile < ApplicationRecord return unless github.valid? add_to_batch(github) if github.commit_batch(github_commit_message) - update_column :github_path, about.github_path_generated + update_column :github_path, manifest_data[:generated_path] end end handle_asynchronously :publish, queue: 'default' @@ -52,7 +52,7 @@ class Communication::Website::GithubFile < ApplicationRecord protected def add_media_to_batch(github) - return unless about.respond_to?(:active_storage_blobs) + return unless manifest_data[:with_media] && about.respond_to?(:active_storage_blobs) about.active_storage_blobs.each { |blob| add_blob_to_batch(github, blob) } end @@ -67,7 +67,7 @@ class Communication::Website::GithubFile < ApplicationRecord end def remove_media_from_github - return unless about.respond_to?(:active_storage_blobs) + return unless manifest_data[:with_media] && about.respond_to?(:active_storage_blobs) about.active_storage_blobs.each { |blob| remove_blob_from_github(blob) } end diff --git a/app/models/concerns/with_github_files.rb b/app/models/concerns/with_github_files.rb index d2d4988ae..5277e84a7 100644 --- a/app/models/concerns/with_github_files.rb +++ b/app/models/concerns/with_github_files.rb @@ -30,7 +30,8 @@ module WithGithubFiles { identifier: "primary", generated_path: github_path_generated, - data: -> (github_file) { to_jekyll(github_file) } + data: -> (github_file) { to_jekyll(github_file) }, + has_media: true } ] end diff --git a/app/services/github.rb b/app/services/github.rb index 84bb565b4..4a4203b28 100644 --- a/app/services/github.rb +++ b/app/services/github.rb @@ -68,6 +68,7 @@ class Github commit = client.create_commit repository, commit_message, new_tree[:sha], branch_sha client.update_branch repository, default_branch, commit[:sha] @tree = nil + true end def remove(path, commit_message) diff --git a/app/views/admin/communication/website/categories/jekyll.html.erb b/app/views/admin/communication/website/categories/jekyll.html.erb index 06f244bdb..5cbc3475a 100644 --- a/app/views/admin/communication/website/categories/jekyll.html.erb +++ b/app/views/admin/communication/website/categories/jekyll.html.erb @@ -2,8 +2,13 @@ title: "<%= @category.name %>" slug: "<%= @category.slug %>" identifier: "<%= @category.id %>" +permalink: "/actualites/<%= @category.slug %>" parent: "<%= @category.parent_id %>" description: > <%= prepare_for_github @category.description, @category.university %> +pagination: + enabled: true + category: <%= @category.id %> + permalink: /:num/ --- <%= @github_file.github_frontmatter.content.html_safe %> diff --git a/app/views/admin/communication/website/categories/jekyll_collection.yml.erb b/app/views/admin/communication/website/categories/jekyll_collection.yml.erb new file mode 100644 index 000000000..054097861 --- /dev/null +++ b/app/views/admin/communication/website/categories/jekyll_collection.yml.erb @@ -0,0 +1,5 @@ +name: <%= @category.name %> +identifier: <%= @category.id %> +link: /actualites/<%= @category.slug %> +parent: <%= @category.parent_id %> +position: <%= @category.position %> -- GitLab