Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasilii Iakliushin <viakliushin@gitlab.com>2020-11-06 18:00:19 +0300
committerVasilii Iakliushin <viakliushin@gitlab.com>2020-11-13 16:24:55 +0300
commit3b063190663f051ca348ca93defacc2991cb2a72 (patch)
tree29be8b126eeb8b6a01bfe9f512eacfa16ccac359
parented69ecf57f1d72d06954b7d756bf6a5a06508414 (diff)
Do not render inactive navigation sidebar sections
Contributes to https://gitlab.com/gitlab-org/gitlab-docs/-/issues/879 It saves up to 50% of the compiled files size
-rw-r--r--layouts/global_nav.html2
-rw-r--r--lib/gitlab/navigation.rb16
-rw-r--r--lib/gitlab/navigation/section.rb7
3 files changed, 24 insertions, 1 deletions
diff --git a/layouts/global_nav.html b/layouts/global_nav.html
index 1bf3795a..f5b587a1 100644
--- a/layouts/global_nav.html
+++ b/layouts/global_nav.html
@@ -12,7 +12,7 @@
</span>
<!-- nav categories -->
- <% if sec.has_children? %>
+ <% if sec.has_children? && sec.enabled %>
<div class="collapse <%= navigation.show_element?(sec) ? 'show' : '' %>" id="<%= navigation.id_for(sec) %>">
<% sec.children.each do |cat| %>
<span class="global-nav-cat nav-link">
diff --git a/lib/gitlab/navigation.rb b/lib/gitlab/navigation.rb
index 022654e0..a3114931 100644
--- a/lib/gitlab/navigation.rb
+++ b/lib/gitlab/navigation.rb
@@ -3,6 +3,8 @@ module Gitlab
def initialize(items, item)
@items = items
@item = item
+
+ disable_inactive_sections!
end
def nav_items
@@ -35,6 +37,20 @@ module Gitlab
attr_reader :items, :item
+ def disable_inactive_sections!
+ return unless is_omnibus?
+
+ children.each do |section|
+ section.disable! unless has_active_element?([section])
+ end
+ end
+
+ def has_active_element?(collection)
+ return false unless collection
+
+ collection.any? { |element| show_element?(element) || has_active_element?(element.children) }
+ end
+
def dir
@dir ||= item.identifier.to_s[%r{(?<=/)[^/]+}]
end
diff --git a/lib/gitlab/navigation/section.rb b/lib/gitlab/navigation/section.rb
index 8b761fb8..82b19d3e 100644
--- a/lib/gitlab/navigation/section.rb
+++ b/lib/gitlab/navigation/section.rb
@@ -3,6 +3,13 @@ module Gitlab
class Section
def initialize(section)
@section = section
+ @enabled = true
+ end
+
+ attr_reader :enabled
+
+ def disable!
+ @enabled = false
end
def title