diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index 97d2e66ecab43b70050247354b30a615a1772a4e..01063ea022dd66719b8d3465b40bc0c6d8b16706 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 ea37392060c98559fed7a497ddf8efb24486a5f6..9fc025e09dc6d402c084fedcd6c6b6692b3e8a8b 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 d2d4988ae25325c0b5dff6af1621f7ca85592720..5277e84a718e363ba24a82407b759a518fa75e85 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 84bb565b47b608d3b8c3dc01978b4c8bbbeb316a..4a4203b28fffbb0832ffca4de3bc433bd24f0585 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 06f244bdba47a2ba4b4190ca651476f5b1bc5eb2..5cbc3475a1c27b019780f50d9474629ca38b8504 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 0000000000000000000000000000000000000000..0540978615b008d51ae672491aea71ecdd6d0bb7 --- /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 %>