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:
authorSarah German <sgerman@gitlab.com>2023-02-10 21:07:45 +0300
committerSuzanne Selhorn <sselhorn@gitlab.com>2023-02-10 21:07:45 +0300
commit41a31cb444e6a981cb63440b09e77cf9821bb8ed (patch)
tree9c995e9e645ddaaa5d5c3af9b2645e339510e6e9 /lib
parenta9f7eb9e2c27b9043d6929b64e2ca60c20a2c2e0 (diff)
Add page section as a metatag
Diffstat (limited to 'lib')
-rw-r--r--lib/helpers/generic.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/helpers/generic.rb b/lib/helpers/generic.rb
index 6fa5fe5f..cfcb8112 100644
--- a/lib/helpers/generic.rb
+++ b/lib/helpers/generic.rb
@@ -53,5 +53,44 @@ module Nanoc::Helpers
def show_banner?
@items['/_data/banner.yaml'][:show_banner]
end
+
+ #
+ # Returns global nav sections.
+ #
+ def get_nav_sections
+ @items['/_data/navigation.yaml'][:sections]
+ end
+
+ #
+ # Get the top-level section for a page, based on the global navigation.
+ #
+ def docs_section(path)
+ path = path[1..] # remove the leading slash
+
+ get_nav_sections.each do |section|
+ section_title = section[:section_title]
+ return section_title if section[:section_url] == path
+
+ section.fetch(:section_categories, []).each do |category|
+ return section_title if category[:category_url] == path
+ next unless category[:docs]
+ return section_title if section_exists?(category[:docs], path)
+ end
+ end
+ nil
+ end
+
+ def section_exists?(docs, path)
+ docs.each do |doc|
+ return true if doc[:doc_url] == path
+
+ sub_docs = doc[:docs]
+ next unless sub_docs
+
+ return true if section_exists?(sub_docs, path)
+ end
+
+ false
+ end
end
end