This is an automated email from the ASF dual-hosted git repository.

andy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jena-site.git


The following commit(s) were added to refs/heads/master by this push:
     new c8ea2c4  Moved breadcrumbs from javascript to be Hugo generated
     new ad05d77  Merge pull request #2 from rlenferink/improve-breadcrumbs
c8ea2c4 is described below

commit c8ea2c41df8069f6d2ccc9c6f3c67c4f29ed4067
Author: Roy Lenferink <[email protected]>
AuthorDate: Wed Mar 4 10:59:26 2020 +0100

    Moved breadcrumbs from javascript to be Hugo generated
---
 layouts/_default/baseof.html      |  7 +++++--
 layouts/partials/breadcrumbs.html | 26 +++++++++++++++++++++++
 static/js/breadcrumbs.js          | 44 ---------------------------------------
 3 files changed, 31 insertions(+), 46 deletions(-)

diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html
index a655965..f13193b 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

Reply via email to