Define site structure in YAML front matter

Adds a site_structure plugin to parse this information, and modify base
template to use this when generating the navbar, instead of hardcoding.
navgroups now mostly automated (i.e. which tab is highlighted on each
page)


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn-site/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn-site/commit/a005e49f
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn-site/tree/a005e49f
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn-site/diff/a005e49f

Branch: refs/heads/master
Commit: a005e49f04bdcae58f480c756f15b19715fa9617
Parents: bc888e6
Author: Richard Downer <[email protected]>
Authored: Thu Aug 21 16:43:08 2014 +0100
Committer: Richard Downer <[email protected]>
Committed: Thu Aug 21 17:48:16 2014 +0100

----------------------------------------------------------------------
 _layouts/base.html                  |  8 +++---
 _plugins/site_structure.rb          | 46 ++++++++++++++++++++++++++++++++
 community/index.md                  |  6 ++++-
 community/migrate-to-apache.md      |  1 -
 documentation.md                    |  1 -
 download.md                         |  1 -
 index.md                            | 12 +++++++++
 learnmore.md                        |  1 -
 quickstart/index.md                 |  3 ++-
 quickstart/policies-and-catalogs.md |  1 -
 10 files changed, 68 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn-site/blob/a005e49f/_layouts/base.html
----------------------------------------------------------------------
diff --git a/_layouts/base.html b/_layouts/base.html
index 7d5e84d..1ae084f 100644
--- a/_layouts/base.html
+++ b/_layouts/base.html
@@ -29,11 +29,9 @@
             <!-- Collect the nav links, forms, and other content for toggling 
-->
             <div class="collapse navbar-collapse" 
id="bs-example-navbar-collapse-1">
                 <ul class="nav navbar-nav navbar-right">
-                    <li class="{% if page.navgroup == 'learnmore' %}active{% 
endif %}"><a href="{{site.url}}/learnmore.html">learn more</a></li>
-                    <li class="{% if page.navgroup == 'download' %}active{% 
endif %}"><a href="{{site.url}}/download.html">download</a></li>
-                    <li class="{% if page.navgroup == 'getstarted' %}active{% 
endif %}"><a href="{{site.url}}/quickstart/">get started</a></li>
-                    <li class="{% if page.navgroup == 'docs' %}active{% endif 
%}"><a href="{{site.url}}/documentation.html">documentation</a></li>
-                    <li class="{% if page.navgroup == 'community' %}active{% 
endif %}"><a href="{{site.url}}/community/">community</a></li>
+                    {% for navgroup in site.data.navgroups %}
+                    <li class="{% if page.navgroup == navgroup.id %}active{% 
endif %}"><a 
href="{{site.url}}{{navgroup.page.url}}">{{navgroup.title}}</a></li><!-- {{ 
navgroup.id }} -->
+                    {% endfor %}
                 </ul>
             </div><!-- /.navbar-collapse -->
         </div><!-- /.container-fluid -->

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn-site/blob/a005e49f/_plugins/site_structure.rb
----------------------------------------------------------------------
diff --git a/_plugins/site_structure.rb b/_plugins/site_structure.rb
new file mode 100644
index 0000000..960d37c
--- /dev/null
+++ b/_plugins/site_structure.rb
@@ -0,0 +1,46 @@
+# Builds a hierarchical structure for the site, based on the YAML front matter 
of each page
+# Starts from a page called "index.md", and follows "children" links in the 
YAML front matter
+module SiteStructure
+  
+  ROOT = "index.md"
+  
+  class Generator < Jekyll::Generator
+    def generate(site)
+      navgroups = site.pages.detect { |page| page.path == SiteStructure::ROOT 
}.data['navgroups']
+      navgroups.each do |ng|
+        ng['page'] = site.pages.detect { |page| page.path == ng['page'] }
+      end
+      puts navgroups
+      site.data['navgroups'] = navgroups
+      site.data['structure'] = gen_structure(site, SiteStructure::ROOT, nil, 
navgroups)
+    end
+    
+    def gen_structure(site, pagename, parent, navgroups)
+      page = site.pages.detect { |page| page.path == pagename }
+      throw "Could not find a page called: #{pagename} (referenced from #{page 
? page.url : nil})" unless page
+      
+      # My navgroup is (first rule matches):
+      # 1. what I have explicitly declared
+      # 2. if I find my path referred to in the global navgroup list
+      # 3. my parent's navgroup
+      unless page.data['navgroup']
+        match = navgroups.detect { |ng| ng['page'] == page }
+        if match
+          page.data['navgroup'] = match['id']
+        elsif parent
+          page.data['navgroup'] = parent.data['navgroup']
+        end
+      end
+      puts "#{page.path} #{page.data['navgroup']}"
+      
+      page.data['parent'] = parent
+      if page.data['children']
+        page.data['children'].each do |c|
+          c['reference'] = gen_structure(site, c['path'], page, navgroups)
+        end
+      end
+      
+      page
+    end
+  end
+end
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn-site/blob/a005e49f/community/index.md
----------------------------------------------------------------------
diff --git a/community/index.md b/community/index.md
index 470c1db..3431ba3 100644
--- a/community/index.md
+++ b/community/index.md
@@ -1,7 +1,11 @@
 ---
 layout: normal
 title: Community
-navgroup: community
+children:
+- { path: community/how-to-contribute.md }
+- { path: community/migrate-to-apache.md }
+- { path: community/committers.md }
+- { path: community/how-to-contribute-docs.md }
 ---
 
 <div class="row">

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn-site/blob/a005e49f/community/migrate-to-apache.md
----------------------------------------------------------------------
diff --git a/community/migrate-to-apache.md b/community/migrate-to-apache.md
index bd1eca8..b5e7bb0 100644
--- a/community/migrate-to-apache.md
+++ b/community/migrate-to-apache.md
@@ -1,7 +1,6 @@
 ---
 layout: normal
 title: How to migrate your brooklyncentral fork to Apache
-navgroup: community
 ---
 
 Prior to our adoption by the Apache Incubator, Brooklyn was developed in a

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn-site/blob/a005e49f/documentation.md
----------------------------------------------------------------------
diff --git a/documentation.md b/documentation.md
index ec25185..436bfc0 100644
--- a/documentation.md
+++ b/documentation.md
@@ -1,7 +1,6 @@
 ---
 layout: normal
 title: Documentation
-navgroup: docs
 ---
 
 ## Official User Manual

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn-site/blob/a005e49f/download.md
----------------------------------------------------------------------
diff --git a/download.md b/download.md
index 485faa9..f169212 100644
--- a/download.md
+++ b/download.md
@@ -1,7 +1,6 @@
 ---
 layout: normal
 title: Download
-navgroup: download
 ---
 
 ## Download Brooklyn Binary Distributions

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn-site/blob/a005e49f/index.md
----------------------------------------------------------------------
diff --git a/index.md b/index.md
index 066473c..59a4ff8 100644
--- a/index.md
+++ b/index.md
@@ -2,6 +2,18 @@
 layout: homepage
 title: Home
 navgroup: home
+children:
+- { path: learnmore.md }
+- { path: download.md }
+- { path: quickstart/index.md }
+- { path: documentation.md }
+- { path: community/index.md }
+navgroups:
+- { id: learnmore, page: learnmore.md, title: learn more }
+- { id: download, page: download.md, title: download }
+- { id: getstarted, page: quickstart/index.md, title: get started }
+- { id: documentation, page: documentation.md, title: documentation }
+- { id: community, page: community/index.md, title: community }
 ---
 
 <div class="jumbotron">

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn-site/blob/a005e49f/learnmore.md
----------------------------------------------------------------------
diff --git a/learnmore.md b/learnmore.md
index 3c02063..42134d2 100644
--- a/learnmore.md
+++ b/learnmore.md
@@ -1,7 +1,6 @@
 ---
 layout: normal
 title: Learn More
-navgroup: learnmore
 ---
 
 <div class="jumobotron" markdown="1">

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn-site/blob/a005e49f/quickstart/index.md
----------------------------------------------------------------------
diff --git a/quickstart/index.md b/quickstart/index.md
index 37a7c45..18b565a 100644
--- a/quickstart/index.md
+++ b/quickstart/index.md
@@ -1,7 +1,8 @@
 ---
 title: Getting Started
 layout: normal
-navgroup: getstarted
+children:
+- { path: quickstart/policies-and-catalogs.md }
 ---
 
 This guide will walk you through deploying an application to a public cloud.

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn-site/blob/a005e49f/quickstart/policies-and-catalogs.md
----------------------------------------------------------------------
diff --git a/quickstart/policies-and-catalogs.md 
b/quickstart/policies-and-catalogs.md
index b57eb3d..7e6723f 100644
--- a/quickstart/policies-and-catalogs.md
+++ b/quickstart/policies-and-catalogs.md
@@ -1,7 +1,6 @@
 ---
 title: Getting Started - Policies and Catalogs
 layout: normal
-navgroup: getstarted
 ---
 
 In the [previous step](index.html) we downloaded Brooklyn and used it to 
deploy an application to a cloud, but at its heart Brooklyn is a policy driven 
*management* plane.

Reply via email to