Refactor showFlags logic

Signed-off-by: hossainemruz <hossainemruz@gmail.com>
This commit is contained in:
hossainemruz 2022-06-13 21:09:16 +06:00
parent 5940a4ea5e
commit 7a2b7904bf
4 changed files with 22 additions and 20 deletions

View file

@ -20,10 +20,5 @@
{{ end }}
{{ end }}
{{/* if specified via "params.showFlags" field, then countryCode is set to be empty. */}}
{{ if eq site.Params.showFlags false }}
{{ $countryCode = "" }}
{{ end }}
{{/* return the country code */}}
{{ return $countryCode }}

View file

@ -5,15 +5,19 @@
<div class="dropdown languageSelector">
<a class="btn dropdown-toggle" href="#" id="languageSelector" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ $countryCode := partial "helpers/country-code.html" . }}
<span class="flag-icon flag-icon-{{$countryCode}}"></span>
{{ if ne site.Params.showFlags false }}
{{ $countryCode := partial "helpers/country-code.html" . }}
<span class="flag-icon flag-icon-{{$countryCode}}"></span>
{{ end }}
{{ site.Language.LanguageName }}
</a>
<div class="dropdown-menu" aria-labelledby="languageSelector">
{{ range .Translations }}
<a class="dropdown-item nav-link languages-item" href="{{ path.Join "/" (cond (eq .Language.Lang "en") "" .Language.Lang) $pageURL }}">
{{ $countryCode := partial "helpers/country-code.html" . }}
<span class="flag-icon flag-icon-{{$countryCode}}"></span>
{{ if ne site.Params.showFlags false }}
{{ $countryCode := partial "helpers/country-code.html" . }}
<span class="flag-icon flag-icon-{{$countryCode}}"></span>
{{ end }}
{{ .Language.LanguageName }}
</a>
{{ end }}

View file

@ -5,17 +5,19 @@
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="languageSelector" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ $countryCode := partial "helpers/country-code.html" . }}
{{ if ne $countryCode "" }}
<span class="flag-icon flag-icon-{{$countryCode}}"></span>
{{ if ne site.Params.showFlags false }}
{{ $countryCode := partial "helpers/country-code.html" . }}
<span class="flag-icon flag-icon-{{$countryCode}}"></span>
{{ end }}
{{ site.Language.LanguageName }}
</a>
<div class="dropdown-menu" aria-labelledby="languageSelector">
{{ range .Translations }}
<a class="dropdown-item nav-link languages-item" href="{{ path.Join "/" (cond (eq .Language.Lang "en") "" .Language.Lang) $pageURL }}">
{{ $countryCode := partial "helpers/country-code.html" . }}
<span class="flag-icon flag-icon-{{$countryCode}}"></span>
{{ if ne site.Params.showFlags false }}
{{ $countryCode := partial "helpers/country-code.html" . }}
<span class="flag-icon flag-icon-{{$countryCode}}"></span>
{{ end }}
{{ .Language.LanguageName }}
</a>
{{ end }}

View file

@ -1,19 +1,20 @@
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="languageSelector" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ $countryCode := partial "helpers/country-code.html" . }}
{{ if ne $countryCode "" }}
<span class="flag-icon flag-icon-{{$countryCode}}"></span>
{{ if ne site.Params.showFlags false }}
{{ $countryCode := partial "helpers/country-code.html" . }}
<span class="flag-icon flag-icon-{{$countryCode}}"></span>
{{ end }}
{{ site.Language.LanguageName }}
</a>
<div class="dropdown-menu" aria-labelledby="languageSelector">
{{ range site.Home.AllTranslations }}
<a class="dropdown-item nav-link languages-item" href="{{ .RelPermalink }}">
{{ $countryCode := partial "helpers/country-code.html" . }}
<span class="flag-icon flag-icon-{{$countryCode}}"></span>
{{ if ne site.Params.showFlags false }}
{{ $countryCode := partial "helpers/country-code.html" . }}
<span class="flag-icon flag-icon-{{$countryCode}}"></span>
{{ end }}
{{ .Language.LanguageName }}
</a>
{{ end }}
</div>
</li>