Hi, i’ve got two different implementations of breadcrumb from this discourse.
<section class="breadcrumb">
{{ $baseurl := .Site.BaseURL }}
{{ $fullurl := print ( .RelPermalink | replaceRE "[^/]+/$" "") }}
<ul class="breadcrumbs">
<li><a href="/" class="crumb">home</a></li>
{{ range $index, $element := split $fullurl "/" }}
{{ $.Scratch.Add "path" $element }}
{{ if ne $element "" }}
<li><a href='{{ $baseurl }}{{ $.Scratch.Get "path" }}'>{{ if isset $.Site.Data.titles . }} {{ index $.Site.Data.titles . }} {{ else }} {{ . }} {{ end }}</a></li>
{{ $.Scratch.Add "path" "/" }}
{{ end }}
{{ end }}
<li>{{ lower .Title }}</li>
</ul>
</section>
<section class="breadcrumb">
{{ $url := replace .Permalink ( printf "%s" .Site.BaseURL) "" }}
{{ $.Scratch.Add "path" .Site.BaseURL }}
{{ $.Scratch.Add "currentURL" .URL }}
<ul>
<li><a href="{{ .Site.BaseURL }}">home</a></li>
{{ range $index, $element := split $url "/" }}
{{ $.Scratch.Add "path" $element }}
{{ $.Scratch.Add "path" "/" }}
<!-- Check if the current list item is the last one -->
{{ $isLast := eq ($.Scratch.Get "path") $.Permalink }}
{{ if ne $element "" }}
{{ if and (not $isLast) }}
<li><a href='{{ $.Scratch.Get "path" }}'>{{ . }}</a></li>
{{ else }}
<li>{{ lower $.Title }}</li>
{{ end }}
{{ end }}
{{ end }}
</ul>
</section>
Take this path for example:
/home/section1
WIth the first implementation i’ve got the last section repeated:
<a href="http://localhost:1313/section1/section1">section1</a>
With the second one:
<a href="http://localhost:1313/section1/subsection1//http://localhost:1313/section1/">section1</a>
The weird thing is, whenever I edit something from the partial snippet code… it gets fixed.
Could it be something from the hugo server -D
itself?