diff --git a/app/models/communication/website/permalink.rb b/app/models/communication/website/permalink.rb index 5329fcc0c3e690ea1beb632dbb1b5214e6c52991..1225fdf117f8037022572e66fcb52b4d9ecacb84 100644 --- a/app/models/communication/website/permalink.rb +++ b/app/models/communication/website/permalink.rb @@ -54,6 +54,7 @@ class Communication::Website::Permalink < ApplicationRecord scope :for_website, -> (website) { where(website_id: website.id) } scope :current, -> { where(is_current: true) } scope :not_current, -> { where(is_current: false) } + scope :not_root, -> { where.not(path: '/') } def self.config_in_website(website, language) required_kinds_in_website(website).map { |permalink_class| diff --git a/app/models/concerns/with_permalink.rb b/app/models/concerns/with_permalink.rb index 8b26356ffd98be4a55cff58d67b31ef652828182..1246b2464b12450cfe25959e1462fd1bb79decc2 100644 --- a/app/models/concerns/with_permalink.rb +++ b/app/models/concerns/with_permalink.rb @@ -9,7 +9,9 @@ module WithPermalink end def previous_permalinks_in_website(website) - permalinks.for_website(website).not_current + permalinks.for_website(website) + .not_current + .not_root end # Persisted in db or nil diff --git a/app/views/admin/application/static/_permalink.html.erb b/app/views/admin/application/static/_permalink.html.erb index 99409ca322c6eebfc6256375bf176c6bbe50c172..6e8fc952573c9ec4272c8041d998dbaeb95a58db 100644 --- a/app/views/admin/application/static/_permalink.html.erb +++ b/app/views/admin/application/static/_permalink.html.erb @@ -4,7 +4,7 @@ url: "<%= @about.current_permalink_in_website(@website)&.path %>" slug: "<%= forced_slug || @about.slug %>" <% end %> <% -previous_permalinks = @about.previous_permalinks_in_website(@website).where.not(path: "/") +previous_permalinks = @about.previous_permalinks_in_website(@website) if previous_permalinks.any? %> aliases: diff --git a/app/views/admin/application/static/_permalink.json.jbuilder b/app/views/admin/application/static/_permalink.json.jbuilder new file mode 100644 index 0000000000000000000000000000000000000000..bae4fabb256a377d868cfeb44392dc130d8521c6 --- /dev/null +++ b/app/views/admin/application/static/_permalink.json.jbuilder @@ -0,0 +1,10 @@ +json.url @about.current_permalink_in_website(@website)&.path + +if @about.respond_to?(:slug) && @about.slug.present? + forced_slug ||= nil + json.slug (forced_slug || @about.slug) +end + +previous_permalinks = @about.previous_permalinks_in_website(@website) +json.aliases previous_permalinks.collect(&:path) if previous_permalinks.any? + \ No newline at end of file diff --git a/app/views/admin/communication/websites/pages/static.json.jbuilder b/app/views/admin/communication/websites/pages/static.json.jbuilder new file mode 100644 index 0000000000000000000000000000000000000000..65a5477b870c0ee5a2983d08b86439c977bdc9e8 --- /dev/null +++ b/app/views/admin/communication/websites/pages/static.json.jbuilder @@ -0,0 +1,5 @@ +json.extract! @page, + :title, + :breadcrumb_title + +json.partial! 'admin/application/static/permalink' \ No newline at end of file