From 75d256b70d7792595a54c89982e75cf1bfe3d77d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com> Date: Fri, 10 Dec 2021 16:47:18 +0100 Subject: [PATCH] authors & posts github directory --- .../communication/websites_controller.rb | 5 ++++- app/models/communication/website.rb | 22 ++++++++++--------- app/models/communication/website/author.rb | 2 +- app/models/communication/website/category.rb | 2 +- .../website/authors/jekyll.html.erb | 2 +- .../website/authors/jekyll_collection.yml.erb | 2 +- .../website/categories/jekyll.html.erb | 2 +- .../categories/jekyll_collection.yml.erb | 2 +- .../communication/websites/_form.html.erb | 2 ++ config/locales/communication/en.yml | 2 ++ config/locales/communication/fr.yml | 2 ++ ...b_directories_to_communication_websites.rb | 6 +++++ db/schema.rb | 4 +++- lib/tasks/app.rake | 5 +++++ 14 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 db/migrate/20211210145958_add_categories_and_authors_github_directories_to_communication_websites.rb diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb index ae9e404ea..86f2e8ca8 100644 --- a/app/controllers/admin/communication/websites_controller.rb +++ b/app/controllers/admin/communication/websites_controller.rb @@ -71,6 +71,9 @@ class Admin::Communication::WebsitesController < Admin::Communication::Applicati protected def website_params - params.require(:communication_website).permit(:name, :url, :repository, :access_token, :about_type, :about_id) + params.require(:communication_website).permit( + :name, :url, :repository, :access_token, :about_type, :about_id, + :authors_github_directory, :posts_github_directory + ) end end diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 15048d7d5..eddce3c46 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -2,16 +2,18 @@ # # Table name: communication_websites # -# id :uuid not null, primary key -# about_type :string -# access_token :string -# name :string -# repository :string -# url :string -# created_at :datetime not null -# updated_at :datetime not null -# about_id :uuid -# university_id :uuid not null +# id :uuid not null, primary key +# about_type :string +# access_token :string +# authors_github_directory :string +# name :string +# posts_github_directory :string +# repository :string +# url :string +# created_at :datetime not null +# updated_at :datetime not null +# about_id :uuid +# university_id :uuid not null # # Indexes # diff --git a/app/models/communication/website/author.rb b/app/models/communication/website/author.rb index 65b8783fb..fe7a41c2c 100644 --- a/app/models/communication/website/author.rb +++ b/app/models/communication/website/author.rb @@ -52,7 +52,7 @@ class Communication::Website::Author < ApplicationRecord # Override from WithGithubFiles def github_path_generated - "auteurs/#{slug}.html" + "#{website.authors_github_directory}/#{slug}.html" end def github_manifest diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index 11a09fe23..014bd9dda 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -78,7 +78,7 @@ class Communication::Website::Category < ApplicationRecord # Override from WithGithubFiles def github_path_generated - "actualites/#{slug}.html" + "#{website.posts_github_directory}/#{slug}.html" end def github_manifest diff --git a/app/views/admin/communication/website/authors/jekyll.html.erb b/app/views/admin/communication/website/authors/jekyll.html.erb index 2f36fcfbd..c0f06a33a 100644 --- a/app/views/admin/communication/website/authors/jekyll.html.erb +++ b/app/views/admin/communication/website/authors/jekyll.html.erb @@ -2,7 +2,7 @@ title: "<%= @author.to_s %>" slug: "<%= @author.slug %>" identifier: "<%= @author.id %>" -permalink: "/auteurs/<%= @author.slug %>" +permalink: "/<%= @author.website.authors_github_directory %>/<%= @author.slug %>" first_name: "<%= @author.first_name %>" last_name: "<%= @author.last_name %>" biography: > diff --git a/app/views/admin/communication/website/authors/jekyll_collection.yml.erb b/app/views/admin/communication/website/authors/jekyll_collection.yml.erb index 301ee362d..f4582d8a1 100644 --- a/app/views/admin/communication/website/authors/jekyll_collection.yml.erb +++ b/app/views/admin/communication/website/authors/jekyll_collection.yml.erb @@ -1,3 +1,3 @@ name: "<%= @author.to_s %>" identifier: "<%= @author.id %>" -link: "/auteurs/<%= @author.slug %>" +link: "/<%= @author.website.authors_github_directory %>/<%= @author.slug %>" diff --git a/app/views/admin/communication/website/categories/jekyll.html.erb b/app/views/admin/communication/website/categories/jekyll.html.erb index 5cbc3475a..39e21da3c 100644 --- a/app/views/admin/communication/website/categories/jekyll.html.erb +++ b/app/views/admin/communication/website/categories/jekyll.html.erb @@ -2,7 +2,7 @@ title: "<%= @category.name %>" slug: "<%= @category.slug %>" identifier: "<%= @category.id %>" -permalink: "/actualites/<%= @category.slug %>" +permalink: "/<%= @category.website.posts_github_directory %>/<%= @category.slug %>" parent: "<%= @category.parent_id %>" description: > <%= prepare_for_github @category.description, @category.university %> diff --git a/app/views/admin/communication/website/categories/jekyll_collection.yml.erb b/app/views/admin/communication/website/categories/jekyll_collection.yml.erb index 1d9d99738..93e6b74fe 100644 --- a/app/views/admin/communication/website/categories/jekyll_collection.yml.erb +++ b/app/views/admin/communication/website/categories/jekyll_collection.yml.erb @@ -1,5 +1,5 @@ name: "<%= @category.name %>" identifier: "<%= @category.id %>" -link: "/actualites/<%= @category.slug %>" +link: "/<%= @category.website.posts_github_directory %>/<%= @category.slug %>" parent: "<%= @category.parent_id %>" position: <%= @category.position %> diff --git a/app/views/admin/communication/websites/_form.html.erb b/app/views/admin/communication/websites/_form.html.erb index 840edae94..b45fcf696 100644 --- a/app/views/admin/communication/websites/_form.html.erb +++ b/app/views/admin/communication/websites/_form.html.erb @@ -37,6 +37,8 @@ <%= f.input :url %> <%= f.input :repository %> <%= f.input :access_token %> + <%= f.input :authors_github_directory %> + <%= f.input :posts_github_directory %> </div> </div> </div> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 431f195b2..948fa94b4 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -60,7 +60,9 @@ en: about_Education::School: School website about_Research::Journal: Journal website about_type: About + authors_github_directory: Authors' GitHub directory name: Name + posts_github_directory: Posts' GitHub directory url: URL communication/website/author: biography: Biography diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index e28bdc957..1ebadc3aa 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -60,7 +60,9 @@ fr: about_Education::School: Site d'école about_Research::Journal: Site de revue scientifique about_type: Sujet du site + authors_github_directory: Dossier GitHub des auteurs name: Nom + posts_github_directory: Dossier GitHub des actualités url: URL communication/website/author: biography: Biographie diff --git a/db/migrate/20211210145958_add_categories_and_authors_github_directories_to_communication_websites.rb b/db/migrate/20211210145958_add_categories_and_authors_github_directories_to_communication_websites.rb new file mode 100644 index 000000000..378d79e0c --- /dev/null +++ b/db/migrate/20211210145958_add_categories_and_authors_github_directories_to_communication_websites.rb @@ -0,0 +1,6 @@ +class AddCategoriesAndAuthorsGithubDirectoriesToCommunicationWebsites < ActiveRecord::Migration[6.1] + def change + add_column :communication_websites, :authors_github_directory, :string + add_column :communication_websites, :posts_github_directory, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 98bd292dd..51550f05c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_12_10_112555) do +ActiveRecord::Schema.define(version: 2021_12_10_145958) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -334,6 +334,8 @@ ActiveRecord::Schema.define(version: 2021_12_10_112555) do t.string "repository" t.string "about_type" t.uuid "about_id" + t.string "authors_github_directory" + t.string "posts_github_directory" t.index ["about_type", "about_id"], name: "index_communication_websites_on_about" t.index ["university_id"], name: "index_communication_websites_on_university_id" end diff --git a/lib/tasks/app.rake b/lib/tasks/app.rake index d5d196178..ce967d665 100644 --- a/lib/tasks/app.rake +++ b/lib/tasks/app.rake @@ -56,6 +56,11 @@ namespace :app do 10.times do Education::Program.find_each { |p| p.update_column :path, "#{p.parent&.path}/#{p.slug}".gsub(/\/+/, '/') } end + + Communication::Website.all.find_each { |website| + website.update_column(:authors_github_directory, "auteurs") if website.authors_github_directory.blank? + website.update_column(:posts_github_directory, "actualites") if website.posts_github_directory.blank? + } end namespace :db do -- GitLab