update breadcrumb and lang-switcher

This commit is contained in:
somrat sorkar 2023-06-04 15:18:31 +06:00
parent 76ed462707
commit 3cc5995449
2 changed files with 18 additions and 12 deletions

View File

@ -1,9 +1,9 @@
{{ $context := .Context }} {{ $context := .Context }}
{{ $class := .Class }} {{ $class := .Class }}
{{ $base := site.BaseURL }} {{ $base := site.BaseURL }}
{{ $url := replace $context.Permalink ( printf "%s" $base) "" }} {{ $pageLink := replace $context.Permalink $base "" }}
{{ $lang := $context.Lang }} {{ $lang := $context.Lang }}
{{ $.Scratch.Add "path" $base }} {{ $context.Scratch.Set "path" "/" }}
<ul class="{{ $class }} inline-flex"> <ul class="{{ $class }} inline-flex">
@ -14,22 +14,28 @@
{{ i18n "home" | default "Home" }} {{ i18n "home" | default "Home" }}
</a> </a>
</li> </li>
{{ range $index, $element := split $url "/" }} {{ range $index, $element := split $pageLink "/" }}
{{ if ne $element $lang }} {{ if ne $element $lang }}
{{ $.Scratch.Add "path" $element }} {{ $context.Scratch.Add "path" $element }}
{{ else }} {{ else }}
{{ $.Scratch.Add "path" (add $element "/") }} {{ $context.Scratch.Add "path" (add $element "/") }}
{{ end }} {{ end }}
{{ if and (ne $element "") (ne $element $lang) }} {{ if and (ne $element "") (ne $element $lang) }}
<li class="text-light dark:text-darkmode-light mx-1 capitalize"> <li class="text-light dark:text-darkmode-light mx-1 capitalize">
<span class="inlin-block mr-1">/</span> <span class="inlin-block mr-1">/</span>
{{ if eq $element (path.BaseName $pageLink) }}
<span class="text-primary dark:text-darkmode-primary">
{{ . }}
</span>
{{ else }}
<a <a
class="text-primary dark:text-darkmode-primary" class="text-primary dark:text-darkmode-primary"
href="{{ $.Scratch.Get `path` }}" href="{{ $context.Scratch.Get `path` }}/">
>{{ . }} {{ . }}
</a> </a>
{{ end }}
</li> </li>
{{ $.Scratch.Add "path" "/" }} {{ $context.Scratch.Add "path" "/" }}
{{ end }} {{ end }}
{{ end }} {{ end }}
</ul> </ul>

View File

@ -4,7 +4,7 @@
{{ $pageLang := $context.Lang }} {{ $pageLang := $context.Lang }}
{{ $base:= urls.Parse site.BaseURL }} {{ $base:= urls.Parse site.BaseURL }}
{{ $siteLanguages := site.Home.AllTranslations }} {{ $siteLanguages := site.Home.AllTranslations }}
{{ $pageLink := replace (replace (replace $context.RelPermalink $pageLang "") "//" "/") $base.Path "" }} {{ $pageLink := replace (replace (replace $context.RelPermalink $pageLang "") "//" "/") $base.Path "/" }}
{{ if $context.IsTranslated }} {{ if $context.IsTranslated }}
<select class="{{ $class }}" onchange="location = this.value"> <select class="{{ $class }}" onchange="location = this.value">