Merge pull request #2 from rlenferink/improve-breadcrumbs
Moved breadcrumbs from javascript to be Hugo generated
diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html
index e380050..ab63f73 100644
--- a/layouts/_default/baseof.html
+++ b/layouts/_default/baseof.html
@@ -32,7 +32,6 @@
crossorigin="anonymous"></script>
<script src="/js/jena-navigation.js" type="text/javascript"></script>
<script src="/js/bootstrap.min.js" type="text/javascript"></script>
- <script src="/js/breadcrumbs.js" type="text/javascript"></script>
<script src="/js/improve.js" type="text/javascript"></script>
@@ -144,7 +143,11 @@
<div class="container">
<div class="row">
<div class="col-md-12">
- <div id="breadcrumbs"></div>
+ <div id="breadcrumbs">
+ {{ if not .IsHome }}
+ {{ partial "breadcrumbs.html" . }}
+ {{ end }}
+ </div>
<h1 class="title">{{ .Title }}</h1>
{{ block "main" . }}{{ end }}
</div>
diff --git a/layouts/partials/breadcrumbs.html b/layouts/partials/breadcrumbs.html
new file mode 100644
index 0000000..7bdfeca
--- /dev/null
+++ b/layouts/partials/breadcrumbs.html
@@ -0,0 +1,26 @@
+{{ $.Scratch.Set "breadcrumb_path" "/" }}
+{{ $.Scratch.Set "url" (replace .Permalink ( printf "%s" .Site.BaseURL) "") }}
+
+{{ $latestChar := substr ($.Scratch.Get "url") (sub (len ($.Scratch.Get "url")) 1) }}
+{{ if eq $latestChar "/" }}
+ {{ $newUrl := substr ($.Scratch.Get "url") 0 (sub (len ($.Scratch.Get "url")) 1) }}
+ {{ $.Scratch.Set "url" $newUrl }}
+{{ end }}
+
+<ol class="breadcrumb">
+ {{ $splittedUrl := split ($.Scratch.Get "url") "/" }}
+ {{ range $index, $element := $splittedUrl }}
+ {{ $.Scratch.Add "breadcrumb_path" $element }}
+ {{ if ne $element "" }}
+ {{ if eq $index (sub (len $splittedUrl) 1) }}
+ <li class="active">{{ upper (replace (humanize .) ".html" "") }}</li>
+ {{ else }}
+ <li><a href='{{ $.Scratch.Get "breadcrumb_path" }}'>{{ upper (replace (humanize .) ".html" "") }}</a></li>
+ {{ end }}
+ {{ $.Scratch.Add "breadcrumb_path" "/" }}
+ {{ end }}
+ {{ end }}
+</ol>
+
+{{ $.Scratch.Delete "breadcrumb_path" }}
+{{ $.Scratch.Delete "url" }}
diff --git a/static/js/breadcrumbs.js b/static/js/breadcrumbs.js
deleted file mode 100644
index 153da29..0000000
--- a/static/js/breadcrumbs.js
+++ /dev/null
@@ -1,44 +0,0 @@
-$(document).ready(function() {
-
- var url = $(location).attr('href');
-
- //Get the name of the domain dynamically
- var prefix = 'http://' + location.host + '/';
- var sslPrefix = 'https://' + location.host + '/';
-
- if(url != prefix && url != prefix + 'index.html' && url != sslPrefix && url != sslPrefix + 'index.html'){
-
- var shortForm = url.replace(prefix, '').replace(sslPrefix, '').replace(/(index)?\.html/g, '').replace(/#.*/g, '');
-
- var crumbs = shortForm.split('/');
-
- if(crumbs[crumbs.length-1] == ""){
- crumbs.pop();
- }
-
- var link = "/";
-
- var breadcrumbs = '<ol class="breadcrumb">';
-
- for (var index = 0; index < crumbs.length; ++index) {
- var crumb = crumbs[index];
- if (crumb.indexOf('?') > -1) crumb = crumb.substring(0, crumb.indexOf('?'));
- link += crumb + '/';
-
- //Check if it is the last element of the array
- if(crumbs.length - 1 == index){
- //If yes then declare as active
- breadcrumbs += '<li class="active">' + crumb.toUpperCase().replace(/_|-/g, ' ') + '</li>';
- }else{
- //if not then print a link for the category
- breadcrumbs += '<li><a href="' + link + '">' + crumb.toUpperCase().replace(/_|-/g, ' ') + '</a></li>';
- }
- }
- breadcrumbs += '</ol>';
- $('#breadcrumbs').append(breadcrumbs);
- }else{
- $('#breadcrumbs').hide();
- }
-});
-
-//update exporter to handle gh-pages