Skip to content

Commit

Permalink
Navbar and Breadcrumbs URL fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gurusabarish committed Oct 26, 2020
1 parent 4ecce56 commit 3ac0329
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 45 deletions.
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ languageCode: "en-us"
title: "Hugo-profile"

googleanalytics: UA-167646412-8
disqusShortname: yourdisqusname
disqusShortname:
Paginate: 3

taxonomies:
Expand Down
2 changes: 1 addition & 1 deletion exampleSite/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: "Hugo-profile"
theme: "hugo-profile"

googleanalytics: UA-xxxxxxx-x
disqusShortname: yourdisqusname
disqusShortname:
Paginate: 3

taxonomies:
Expand Down
54 changes: 13 additions & 41 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,22 @@ <h1>{{.Title}}</h1>
</div>

<div>
{{ $siteUrl := replace .Permalink ( printf "%s" .Site.BaseURL) "" }}
{{ $.Scratch.Add "sitePath" .Site.BaseURL }}

{{ $.Scratch.Add "siteBreadcrumbs" (slice (dict "url" .Site.BaseURL "name" "home" "position" 1 )) }}
{{ range $index, $element := split $siteUrl "/" }}
{{ $.Scratch.Add "sitePath" $element }}
{{ $.Scratch.Add "sitePath" "/" }}
{{ if ne $element "" }}
{{ $.Scratch.Add "siteBreadcrumbs" (slice (dict "url" ($.Scratch.Get "sitePath") "name" . "position" (add $index 2))) }}
{{ end }}
{{ end }}

<nav aria-label="breadcrumb">
<ol class="breadcrumb">
{{ range $.Scratch.Get "siteBreadcrumbs" }}
<li class="breadcrumb-item" aria-current="page"><a href="{{ .url }}"> {{ .name }} </a></li>
<!-- Initialise a scratch variable "path" to an empty string -->
{{ $.Scratch.Set "path" "" }}
<li><a href="/">Home</a></li>
<!-- For each non-empty item in the URL path -->
{{ range $element := split .RelPermalink "/" }}
{{ if ne $element "" }}
<!-- Add the element to the scratch variable -->
{{ $.Scratch.Add "path" "/" }}{{ $.Scratch.Add "path" $element }}
<!-- Populate the href from the scratch variable -->
<span class="text-muted px-2">/</span>
<li><a href="{{ $.Scratch.Get "path" }}">{{ humanize . }}</a></li>
{{ end }}
{{ end }}
</ol>
</nav>
</div>
<!-- image -->
Expand Down Expand Up @@ -233,32 +232,5 @@ <h5 class="card-header m-0">Tags</h5>
</div>
</div>
</div>

{{ $url := replace .Permalink ( printf "%s" .Site.BaseURL) "" }}
{{ $.Scratch.Add "path" .Site.BaseURL }}

{{ $.Scratch.Add "breadcrumb" (slice (dict "url" .Site.BaseURL "name" "home" "position" 1 )) }}
{{ range $index, $element := split $url "/" }}
{{ $.Scratch.Add "path" $element }}
{{ $.Scratch.Add "path" "/" }}
{{ if ne $element "" }}
{{ $.Scratch.Add "breadcrumb" (slice (dict "url" ($.Scratch.Get "path") "name" . "position" (add $index 2))) }}
{{ end }}
{{ end }}

<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [{{ range $.Scratch.Get "breadcrumb" }}{{ if ne .position 1 }},{{ end }}{
"@type": "ListItem",
"position": {{ .position }},
"item": {
"@id": "{{ .url }}",
"name": "{{ .name }}"
}
}{{ end }}]
}
</script>
</section>
{{ end }}
4 changes: 2 additions & 2 deletions layouts/partials/header.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm sticky-top">
<div class="container">
<a class="navbar-brand font-weight-bold" href="{{ .Site.BaseURL }}">
<a class="navbar-brand font-weight-bold" href="{{ .Site.BaseURL | relURL }}">
{{ if .Site.Params.favicon }}
<img src="{{ .Site.Params.favicon }}" width="30" height="30" class="d-inline-block align-top"
alt="{{ .Site.Title }}">
Expand All @@ -17,7 +17,7 @@
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav ml-auto text-center">
<li class="nav-item navbar-text">
<a class="nav-link" href="{{ .Site.BaseURL }}#" aria-label="about">About</a>
<a class="nav-link" href="{{ .Site.BaseURL | relURL }}#" aria-label="about">About</a>
</li>

{{ range site.Params.customMenus }}
Expand Down

0 comments on commit 3ac0329

Please sign in to comment.