-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ breadcrumbs: Use Hugo-native script instead of JavaScript (#138)
This commit refactors the existing breadcrumb bar to use a Hugo-native way of constructing the path. It also removes the duplicate "Home" and site title options, so the view is cleaner. Related to PR #133.
- Loading branch information
Showing
2 changed files
with
16 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
<script language="JavaScript"> | ||
|
||
String.prototype.capitalizeFirstLetter = function() { | ||
return this.charAt(0).toUpperCase() + this.slice(1); | ||
} | ||
|
||
var path = "<a style='margin-left:2%' href='{{ .Site.BaseURL}}'>Home</a>"; | ||
var href = document.location.href; | ||
var s = href.split("/"); | ||
for (var i=3;i<(s.length-2);i++) { | ||
path+=" > <a href=\""+href.substring(0,href.indexOf("/"+s[i])+s[i].length+1)+"/\">"+s[i].capitalizeFirstLetter()+"</a> "; | ||
} | ||
i=s.length-1; | ||
path+="<a href=\""+href.substring(0,href.indexOf(s[i])+s[i].length)+"\">"+s[i]+"</a>"; | ||
path+=" > <b>{{.Title}}</b>"; | ||
document.writeln(path); | ||
</script> | ||
{{ $url := replace .Permalink ( printf "%s" .Site.BaseURL) "" }} | ||
{{ $.Scratch.Add "path" .Site.BaseURL }} | ||
<div class="breadcrumbs"> | ||
<a href="{{ .Site.BaseURL}}">Home</a> | ||
{{ range $index, $element := split $url "/" }} | ||
{{ $.Scratch.Add "path" $element }} | ||
{{ if ne $element "" }} | ||
> <a href="{{ $.Scratch.Get "path" }}" class="breadcrumbLink">{{ . }}</a> | ||
{{ $.Scratch.Add "path" "/" }} | ||
{{ end }} | ||
{{ end }} | ||
</div> |