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
path: root/lib
diff options
context:
space:
mode:
authorVasilii Iakliushin <viakliushin@gitlab.com>2020-11-06 18:00:19 +0300
committerVasilii Iakliushin <viakliushin@gitlab.com>2020-11-16 23:23:39 +0300
commit2948b293efd2929944eaabfefcdd0f8c4465a06c (patch)
tree5b1bb5a27a621b281d654c0f5e812cc069d787f5 /lib
parent43e56b085a8176c82c39148ba8a2c003742e4b55 (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
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/navigation.rb20
-rw-r--r--lib/gitlab/navigation/section.rb7
-rw-r--r--lib/helpers/generic.rb4
3 files changed, 31 insertions, 0 deletions
diff --git a/lib/gitlab/navigation.rb b/lib/gitlab/navigation.rb
index 052cdad5..ae5dbe9c 100644
--- a/lib/gitlab/navigation.rb
+++ b/lib/gitlab/navigation.rb
@@ -1,8 +1,14 @@
+require_relative '../helpers/generic'
+
module Gitlab
class Navigation
+ include Nanoc::Helpers::Generic
+
def initialize(items, item)
@items = items
@item = item
+
+ disable_inactive_sections!
end
def nav_items
@@ -35,6 +41,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
diff --git a/lib/helpers/generic.rb b/lib/helpers/generic.rb
index 2bc27ea8..5e5ea01b 100644
--- a/lib/helpers/generic.rb
+++ b/lib/helpers/generic.rb
@@ -8,5 +8,9 @@ module Nanoc::Helpers
def is_production?
ENV['NANOC_ENV'] == 'production'
end
+
+ def is_omnibus?
+ ENV['NANOC_ENV'] == 'omnibus'
+ end
end
end