From fd33efc0d76e3f21f170ea113c42f42135c9a374 Mon Sep 17 00:00:00 2001 From: Hardy Ferentschik Date: Sun, 23 Apr 2017 23:42:45 +0200 Subject: [PATCH] Issue #721 Using topic map to generate navigation --- docs/Rakefile | 2 +- docs/helpers/custom_helpers.rb | 54 +++++++++++++ docs/source/layouts/layout.erb | 134 +-------------------------------- 3 files changed, 56 insertions(+), 134 deletions(-) create mode 100644 docs/helpers/custom_helpers.rb diff --git a/docs/Rakefile b/docs/Rakefile index 9b22175ea3..bf49dbe970 100644 --- a/docs/Rakefile +++ b/docs/Rakefile @@ -58,7 +58,7 @@ end desc 'Generate site' task :gen => [:init, :markdown_to_asciidoc, :adoc_variables] do - sh "bundle exec middleman build" + sh "bundle exec middleman build --no-clean" end desc 'Serve site' diff --git a/docs/helpers/custom_helpers.rb b/docs/helpers/custom_helpers.rb new file mode 100644 index 0000000000..b07f7c95a2 --- /dev/null +++ b/docs/helpers/custom_helpers.rb @@ -0,0 +1,54 @@ +require 'yaml' + +module CustomHelpers + + def navigation_menu + navigation = "" + topic_map = YAML.load_file('build/_topic_map.yml') + topic_map["Topics"].each_with_index do |topic, index| + topic_directory = topic["Dir"] + if topic_directory.nil? + next "
  •  #{topic["Name"]}
  • " + end + + caret = "fa-caret-right" + in_class = "" + subnav = "" + entries = "" + sub_topics = topic["Topics"] + unless sub_topics.nil? + sub_topics.each do |subtopic| + path = current_page.url + sub_topic_file = subtopic["File"] + sub_topic_name = subtopic["Name"] + if !path.end_with?("html") + path += "index.html" + end + if path == "/#{topic_directory}/#{sub_topic_file}.html" + in_class = "in" + caret = "fa-caret-down" + entries += "
  •  #{sub_topic_name}
  • " + else + entries += "
  •  #{sub_topic_name}
  • " + end + end + + subnav += "" + end + + topic_nav = <<-HEREDOC + + HEREDOC + navigation += topic_nav % [index, index, caret, topic["Name"], subnav] + end + + navigation + end +end diff --git a/docs/source/layouts/layout.erb b/docs/source/layouts/layout.erb index 871a6fe38d..a1d34feb75 100644 --- a/docs/source/layouts/layout.erb +++ b/docs/source/layouts/layout.erb @@ -72,139 +72,7 @@ Minishift