diff --git a/app/controllers/admin/communication/website/pages_controller.rb b/app/controllers/admin/communication/website/pages_controller.rb index 5f56a8bdedf35155e05a769a093437a9e86bb552..426870e145c24c869d87935f34732a45badd5ff2 100644 --- a/app/controllers/admin/communication/website/pages_controller.rb +++ b/app/controllers/admin/communication/website/pages_controller.rb @@ -29,6 +29,11 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web breadcrumb end + def publish + @page.force_publish! + redirect_to admin_communication_website_page_path(@page), notice: t('admin.will_be_published_html', model: @page.to_s) + end + def new @page.website = @website breadcrumb diff --git a/app/controllers/admin/communication/website/posts_controller.rb b/app/controllers/admin/communication/website/posts_controller.rb index d21f53f8dd2d6b79938f12b54f7ee9c471f2a8b8..c3b7128a7a6c7638d150fe3c27e15288077579fa 100644 --- a/app/controllers/admin/communication/website/posts_controller.rb +++ b/app/controllers/admin/communication/website/posts_controller.rb @@ -10,6 +10,11 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web breadcrumb end + def publish + @post.force_publish! + redirect_to admin_communication_website_post_path(@post), notice: t('admin.will_be_published_html', model: @post.to_s) + end + def new @post.website = @website breadcrumb diff --git a/app/models/communication/website/imported/website.rb b/app/models/communication/website/imported/website.rb index d758f8456747e04e0ebe88024430c2046e0d144b..70f15a1b64d55142780b3fad9d417a4634870f23 100644 --- a/app/models/communication/website/imported/website.rb +++ b/app/models/communication/website/imported/website.rb @@ -95,6 +95,11 @@ class Communication::Website::Imported::Website < ApplicationRecord github.add_to_batch path: page.github_path_generated, previous_path: page.github_path, data: page.to_jekyll + page.active_storage_blobs.each do |blob| + blob.analyze unless blob.analyzed? + github.add_to_batch path: page.blob_github_path_generated(blob), + data: page.blob_to_jekyll(blob) + end end github.commit_batch '[Page] Batch update from import' end @@ -116,6 +121,11 @@ class Communication::Website::Imported::Website < ApplicationRecord github.add_to_batch path: generated_post.github_path_generated, previous_path: generated_post.github_path, data: generated_post.to_jekyll + generated_post.active_storage_blobs.each do |blob| + blob.analyze unless blob.analyzed? + github.add_to_batch path: generated_post.blob_github_path_generated(blob), + data: generated_post.blob_to_jekyll(blob) + end end end github.commit_batch '[Post] Batch update from import' if github.valid? diff --git a/app/models/communication/website/with_media.rb b/app/models/communication/website/with_media.rb index e25ffb8d2907211935db61e8853ff558af6255a2..10c6357737c153eff1d3c6c3f721206d03f516f5 100644 --- a/app/models/communication/website/with_media.rb +++ b/app/models/communication/website/with_media.rb @@ -1,13 +1,21 @@ module Communication::Website::WithMedia extend ActiveSupport::Concern - protected - def active_storage_blobs blob_ids = [featured_image&.blob_id, text.embeds.blobs.pluck(:id)].flatten.compact university.active_storage_blobs.where(id: blob_ids) end + def blob_to_jekyll(blob) + ApplicationController.render( + template: 'active_storage/blobs/jekyll', + layout: false, + assigns: { blob: blob } + ) + end + + protected + def publish_to_github super active_storage_blobs.each do |blob| @@ -17,12 +25,4 @@ module Communication::Website::WithMedia data: blob_to_jekyll(blob)) end end - - def blob_to_jekyll(blob) - ApplicationController.render( - template: 'active_storage/blobs/jekyll', - layout: false, - assigns: { blob: blob } - ) - end end diff --git a/app/models/concerns/with_github.rb b/app/models/concerns/with_github.rb index ab6366b2d11431d59a4b3ace878b713c5e3d920b..65fea1ba15a4a4915f162202402ef9e0db24d7d4 100644 --- a/app/models/concerns/with_github.rb +++ b/app/models/concerns/with_github.rb @@ -5,6 +5,10 @@ module WithGithub after_save :publish_to_github end + def force_publish! + publish_to_github + end + def github_content @content ||= github.read_file_at github_path end diff --git a/app/views/admin/communication/website/pages/show.html.erb b/app/views/admin/communication/website/pages/show.html.erb index bd13c0218f422705a405c2050c330ae687b4bfb5..6a0bc6cdefa0588c78a7aa1e91eb2c2db9b1ec98 100644 --- a/app/views/admin/communication/website/pages/show.html.erb +++ b/app/views/admin/communication/website/pages/show.html.erb @@ -80,6 +80,13 @@ </div> </div> +<% content_for :action_bar_left do %> + <%= link_to t('communication.website.force_publication'), + publish_admin_communication_website_page_path(@page), + method: :post, + class: button_classes %> +<% end %> + <% content_for :action_bar_right do %> <%= edit_link @page %> <% end %> diff --git a/app/views/admin/communication/website/posts/show.html.erb b/app/views/admin/communication/website/posts/show.html.erb index 1a3b94788cc00c5f2e1eb445287d959f5fb4ea5c..3e44d2c44717b3f2008b6ac925dd947d903a8d86 100644 --- a/app/views/admin/communication/website/posts/show.html.erb +++ b/app/views/admin/communication/website/posts/show.html.erb @@ -69,6 +69,13 @@ </div> </div> +<% content_for :action_bar_left do %> + <%= link_to t('communication.website.force_publication'), + publish_admin_communication_website_post_path(@post), + method: :post, + class: button_classes %> +<% end %> + <% content_for :action_bar_right do %> <%= edit_link @post %> <% end %> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 8e4ad0baa28fb133c64f7ea02385eb05dc5bbc71..1b28d20a7503f85c418c29f529f87e31167b0eca 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -1,6 +1,7 @@ en: communication: website: + force_publication: 'Force publication' imported: from: Imported from launch: Launch import diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 197557fd7fc2f6df686fe39284eabe8cf8b80532..8a117d0fff16274e00e1d5a8392a44dc9f5275ec 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -1,6 +1,7 @@ fr: communication: website: + force_publication: 'Forcer la publication' imported: from: Importé depuis launch: Importer le site diff --git a/config/locales/en.yml b/config/locales/en.yml index 7e56b2cc98822272d3d22a48ee382e40cdf93d2d..683b157c97705fe0fecddbfab1ccd54fa9623697 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -47,6 +47,7 @@ en: users_alerts: not_locked_html: '<i>%{model}</i> was not locked.' successfully_unlocked_html: "<i>%{model}</i> was successfully unlocked." + will_be_published_html: "<i>%{model}</i> will soon be published." content: Content cookies_consent_choice: Cookies consent choice cookies_policy: Cookies policy diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 14a54f555c51d08f80a5da1ff2b3dafbb5b44571..b36549ec4278ac475139f9c2b9545e437ed55128 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -47,6 +47,7 @@ fr: users_alerts: not_locked_html: "<i>%{model}</i> n'était pas verrouillé(e)." successfully_unlocked_html: "<i>%{model}</i> a bien été déverrouillé(e)." + will_be_published_html: "<i>%{model}</i> va bientôt être publié(e)." content: Contenu cookies_consent_choice: Choix en matière de cookies cookies_policy: Politique de cookies diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index 46430d09ced246a311c3bd70ffe03e2722c8c1e6..c335393f7c8fe2ba8c847b817f8566de61002c37 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -10,6 +10,7 @@ namespace :communication do end member do get :children + post :publish end end resources :categories, controller: 'website/categories' do @@ -21,7 +22,11 @@ namespace :communication do end end resources :authors, controller: 'website/authors' - resources :posts, controller: 'website/posts' + resources :posts, controller: 'website/posts' do + member do + post :publish + end + end resources :menus, controller: 'website/menus' do resources :items, controller: 'website/menu/items', except: :index do collection do