use the Jekyll pages information to create the menu
authorRalf Jung <post@ralfj.de>
Wed, 7 Oct 2015 14:44:03 +0000 (16:44 +0200)
committerRalf Jung <post@ralfj.de>
Wed, 7 Oct 2015 14:44:03 +0000 (16:44 +0200)
_config.yml
_includes/menu-level.html
_layouts/default.html
_plugins/menu.rb [new file with mode: 0644]
feed.xml
index.html

index be1260fa4708c5380cd964cd0a591c40308f6d72..83ead923c84745b9280e3af305b75b0dd4afac6a 100644 (file)
@@ -1,25 +1,10 @@
 # Site settings
-title: ralfj.de
 url: "https://www.ralfj.de"
 
 blog:
     title: "Ralf's Ramblings"
     description: "Ralf rambling on things"
 
-structure:
-  - url: "/"
-    title: "ralfj.de"
-    structure:
-      - url: "projects/"
-        title: "Projects"
-        structure:
-          - url: "lilass/"
-            title: LiLaSS
-          - url: "schsh/"
-            title: schsh
-      - url: "cs/"
-        title: "Research"
-
 defaults:
   - scope:
       path: "" # all files in the project
index 0b25bd7ec65fe27376317dfdd3b3f1ec8f82b181..5f5ac469dcc8e79e609613aca88204f79e2b4816 100644 (file)
@@ -1,12 +1,6 @@
-<ul>{% for item in include.menu %}<!--
-    {% comment %} We compute the full URL of this item, and truncate canonicalurl so that length so we can test whether it starts with it {% endcomment %}
-    {% assign cururl = item.url | prepend: include.base %}
-    {% assign isparent_search = canonicalurl | truncate: cururl.size, '' %}
-    {% capture class %}{% if cururl == canonicalurl %}current{% elsif include.above != true %}child{% elsif isparent_search == cururl %}parent{% else %}sibling{% endif %}{% endcapture %}
-    {% comment %} Now we can output the item and it substructure. Try hard not to output unnecessary spaces! {% endcomment %}
-    --><li class="{{ class }}"><a href="{{ item.url | prepend: include.base }}">{{ item.title }}</a></li><!--
-    {% if item.structure and (class == "current" or class == "parent") %}
-        {% if cururl == canonicalurl %}{% assign above = false %}{% else %}{% assign above = true %}{% endif %}
-        -->{% include menu-level.html menu=item.structure base=cururl above=above %}<!--
+<ul><!--{% for item in include.menu %}
+    --><li class="{{ item.class }}"><a href="{{ item.url }}">{{ item.url }}: {{ item.title }}</a></li><!--
+    {% if item.sub %}
+        -->{% include menu-level.html menu=item.sub %}<!--
     {% endif %}
--->{% endfor %}</ul>
\ No newline at end of file
+{% endfor %}--></ul>
\ No newline at end of file
index 5fe8d4d67a6fd4f0f37a53667642429e227b75c1..cff4389b9f615936a127fae8423131098fcee3a3 100644 (file)
@@ -5,28 +5,29 @@
     <meta charset="utf-8">
     <meta name="viewport" content="width=device-width">
 
-    <title>{% if page.title %}{{ page.title }}{% else %}{{ site.title }}{% endif %}</title>
+    <title>{{ page.title }}</title>
     {% if page.excerpt %}<meta name="description" content="{{ page.excerpt | strip_html | strip_newlines | truncate: 160 }}">{% endif %}
 
     <link rel="stylesheet" href="/style.css">
     {% capture canonicalurl %}{{ page.url | replace:'index.html','' }}{% endcapture %}
     <link rel="canonical" href="{{ canonicalurl | prepend: site.url }}">
-    {% if page.rss or page.layout == 'post' %}<link rel="alternate" type="application/rss+xml" title="{{ site.title }}" href="{{ "/feed.xml" | prepend: site.url }}" />{% endif %}
+    {% if page.rss or page.layout == 'post' %}<link rel="alternate" type="application/rss+xml" title="{{ site.blog.title }}" href="/feed.xml" />{% endif %}
   </head>
 
 
   <body><div id="-frame">
   
     <header id="-title">
-      <h1>{% if page.title %}{{ page.title }}{% else %}{{ site.title }}{% endif %}</h1>
+      <h1>{{ page.title }}</h1>
     </header>
 
     <nav id="-navi">
-        {% include menu-level.html menu=site.structure base="" above=true %}
+      {% assign menu = site.html_pages | menu: page.url %}
+      {% include menu-level.html menu=menu %}
     </nav>
 
     <article id="-content">
-        {{ content }}
+      {{ content }}
     </article>
 
   </div></body>
diff --git a/_plugins/menu.rb b/_plugins/menu.rb
new file mode 100644 (file)
index 0000000..317db0c
--- /dev/null
@@ -0,0 +1,40 @@
+module Jekyll
+    module MenuFilter
+        def menu(input, displayurl)
+            def create_menu(pages, base, displayurl)
+                result = Array.new
+                for page in pages
+                    cururl = page['url'].sub('/index.html', '')
+                    if cururl.start_with?(base) and cururl.count('/') == base.count('/')
+                        # figure out CSS class
+                        if cururl == displayurl
+                            css_class = 'current'
+                        elsif cururl.start_with?(displayurl)
+                            css_class = 'child'
+                        elsif displayurl.start_with?(cururl)
+                            css_class = 'parent'
+                        else
+                            css_class = 'sibling'
+                        end
+                        # create menu node
+                        menu_node = { 'url' => page['url'], 'title' => page['title'], 'class' => css_class }
+                        # potentially recurse
+                        if (css_class == 'parent' or css_class == 'current')
+                            sub_nodes = create_menu(pages, cururl + "/", displayurl)
+                            if sub_nodes.size > 0
+                                menu_node['sub'] = sub_nodes
+                            end
+                        end
+                        # store menu node
+                        result.push(menu_node)
+                    end
+                end
+                result
+            end
+            
+            create_menu(input, "", displayurl.sub('/index.html', ''))
+        end
+    end
+end
+
+Liquid::Template.register_filter(Jekyll::MenuFilter)
index 0405375b4328af1eef860049a883f61eb03ccf45..05bc7f0e054098a3c266191931ea862066d50bf3 100644 (file)
--- a/feed.xml
+++ b/feed.xml
@@ -7,7 +7,7 @@ layout: null
     <title>{{ site.blog.title | xml_escape }}</title>
     <description>{{ site.blog.description | xml_escape }}</description>
     <link>{{ site.url }}/</link>
-    <atom:link href="{{ "/feed.xml" | prepend: site.baseurl | prepend: site.url }}" rel="self" type="application/rss+xml"/>
+    <atom:link href="{{ "/feed.xml" | prepend: site.url }}" rel="self" type="application/rss+xml"/>
     <pubDate>{{ site.time | date_to_rfc822 }}</pubDate>
     <lastBuildDate>{{ site.time | date_to_rfc822 }}</lastBuildDate>
     <generator>Jekyll v{{ jekyll.version }}</generator>
@@ -16,8 +16,8 @@ layout: null
         <title>{{ post.title | xml_escape }}</title>
         <description>{{ post.content | xml_escape }}</description>
         <pubDate>{{ post.date | date_to_rfc822 }}</pubDate>
-        <link>{{ post.url | prepend: site.baseurl | prepend: site.url }}</link>
-        <guid isPermaLink="true">{{ post.url | prepend: site.baseurl | prepend: site.url }}</guid>
+        <link>{{ post.url | prepend: site.url }}</link>
+        <guid isPermaLink="true">{{ post.url | prepend: site.url }}</guid>
         {% for tag in post.tags %}
         <category>{{ tag | xml_escape }}</category>
         {% endfor %}
index 326d04398b8d379644fa7f2e9120104ce15c010b..c46238cad557e1187fa249acff714133aee03dfa 100644 (file)
@@ -1,4 +1,5 @@
 ---
+title: ralfj.de
 ---
 
 <h2>Willkommen</h2>