diff --git a/app/models/communication/website/menu/item.rb b/app/models/communication/website/menu/item.rb index e923cf9238ae1e37393acae9f25969c265deb41a..707c9f7bf940aa34ea0243e95fa70cebda540ff1 100644 --- a/app/models/communication/website/menu/item.rb +++ b/app/models/communication/website/menu/item.rb @@ -73,31 +73,34 @@ class Communication::Website::Menu::Item < ApplicationRecord end def static_target - target = '' + target = nil case self.kind when 'url' target = url + when 'page', 'news_article' + target = about.path if about&.published_at when 'programs' - target = "/#{website.programs_github_directory}" + target = "/#{website.programs_github_directory}" if website.programs.any? when 'program' - target = "/#{website.programs_github_directory}#{about.path}" + target = "/#{website.programs_github_directory}#{about.path}" if website.about_school? when 'news' - target = "/#{website.posts_github_directory}" + target = "/#{website.posts_github_directory}" if website.posts.published.any? when 'staff' - target = "/#{website.staff_github_directory}" + target = "/#{website.staff_github_directory}" if website.people.any? when 'research_volumes' - target = "/#{website.research_volumes_github_directory}" + target = "/#{website.research_volumes_github_directory}" if website.research_volumes.published.any? when 'research_volume' - target = "/#{website.research_volumes_github_directory}#{about.path}" + target = "/#{website.research_volumes_github_directory}#{about.path}" if about&.published_at when 'research_articles' - target = "/#{website.research_articles_github_directory}" + target = "/#{website.research_articles_github_directory}" if website.research_articles.published.any? when 'research_article' - target = "/#{website.research_articles_github_directory}#{about.path}" + target = "/#{website.research_articles_github_directory}#{about.path}" if about&.published_at when 'blank' target = '' else target = about&.path end + return nil if target.nil? target.end_with?('/') ? target : "#{target}/" end @@ -112,12 +115,12 @@ class Communication::Website::Menu::Item < ApplicationRecord end def to_static_hash - return {} if kind_news_article? && !about.published + return nil if static_target.nil? { 'title' => title, 'target' => static_target, 'kind' => kind, - 'children' => children.ordered.map(&:to_static_hash) + 'children' => children.ordered.map(&:to_static_hash).compact } end diff --git a/app/views/admin/communication/website/menus/static.html.erb b/app/views/admin/communication/website/menus/static.html.erb index 035a94b4a3a9e6728b0935912c0ee4d6b17e15ff..8e9ef0627777b377da62295cad320fea0514c1e1 100644 --- a/app/views/admin/communication/website/menus/static.html.erb +++ b/app/views/admin/communication/website/menus/static.html.erb @@ -2,4 +2,5 @@ .root .ordered .map(&:to_static_hash) + .compact .to_yaml %>