Skip to content

Commit e413a6a

Browse files
authored
Merge pull request #1606 from gethinode/develop
feat: enable optional inline language selector
2 parents d445912 + df88d86 commit e413a6a

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

assets/scss/components/_navbar.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,17 @@
392392
.form-control.is-search {
393393
border: 1px solid var(--bs-border-color) !important;
394394
}
395+
396+
.inline-menu li {
397+
display: inline-block;
398+
padding: 0.5rem;
399+
color: var(--bs-nav-link-color);
400+
}
401+
402+
.inline-menu li .active, .inline-menu li>a:hover {
403+
box-shadow: inset 0 -1px 0 var(--bs-navbar-hover-color);
404+
}
405+
406+
ul.inline-menu {
407+
padding: 0;
408+
}

exampleSite/config/_default/params.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
maxNumHeadings = 9
6262
[navigation.language]
6363
icon = "fas globe"
64+
inline = false
6465
[navigation.padding]
6566
x = 4
6667
y = 4

layouts/_partials/assets/helpers/navbar-languages.html

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,39 @@
44
{{- $pretty := .pretty -}}
55
{{- $icon := .icon | default "fas globe" -}}
66
{{- $fs := .fs | default 6 -}}
7+
{{- $inline := site.Params.navigation.language.inline | default false -}}
8+
{{- $class := cond $inline "inline-menu" "dropdown-menu dropdown-menu-end" }}
79

810
{{- $lang := $page.Language.Lang -}}
911
<li class="nav-item dropdown me-auto">
10-
<a class="nav-link dropdown-toggle d-{{ $breakpoint }}-none" role="button" data-bs-toggle="dropdown"
11-
aria-label="{{ T "languageSwitcherLabel" }}" aria-expanded="false">
12-
{{- partial "assets/icon.html" (dict "icon" (printf "%s fa-fw" $icon) "spacing" true) }}{{ T "languageSwitcherLabel" }}
13-
</a>
14-
<a class="nav-link dropdown-toggle d-none d-{{ $breakpoint }}-block" role="button" data-bs-toggle="dropdown"
15-
aria-label="{{ T "languageSwitcherLabel" }}" aria-expanded="false">
16-
{{- partial "assets/icon.html" (dict "icon" (printf "%s fa-fw" $icon) "spacing" false) }}
17-
</a>
18-
<ul id="language-selector" class="dropdown-menu dropdown-menu-end navbar-fs-{{ $fs }} navbar-{{ $breakpoint }}-fs" data-translated="{{ $page.IsTranslated }}">
12+
{{ if not $inline }}
13+
<a class="nav-link dropdown-toggle d-{{ $breakpoint }}-none" role="button" data-bs-toggle="dropdown"
14+
aria-label="{{ T "languageSwitcherLabel" }}" aria-expanded="false">
15+
{{- partial "assets/icon.html" (dict "icon" (printf "%s fa-fw" $icon) "spacing" true) }}{{ T "languageSwitcherLabel" }}
16+
</a>
17+
<a class="nav-link dropdown-toggle d-none d-{{ $breakpoint }}-block" role="button" data-bs-toggle="dropdown"
18+
aria-label="{{ T "languageSwitcherLabel" }}" aria-expanded="false">
19+
{{- partial "assets/icon.html" (dict "icon" (printf "%s fa-fw" $icon) "spacing" false) }}
20+
</a>
21+
{{ end }}
22+
<ul id="language-selector" class="{{ $class }} navbar-fs-{{ $fs }} navbar-{{ $breakpoint }}-fs" data-translated="{{ $page.IsTranslated }}">
1923
{{- if $page.IsTranslated -}}
2024
{{- range $page.AllTranslations -}}
2125
<li>
2226
{{- $state := cond (eq .Language.Lang $lang) "active" "" }}
2327
<a class="dropdown-item {{ $state }}" hreflang="{{ .Language.Lang }}" href="{{ .RelPermalink }}">
24-
{{- .Language.LanguageName -}}
28+
{{- cond $inline (upper .Language.Lang) .Language.LanguageName -}}
2529
</a>
2630
</li>
2731
{{- end -}}
2832
{{- else -}}
2933
{{- range site.Languages -}}
30-
{{ $dest := partial "utilities/URLJoin.html" (dict "base" $baseURL "path" .Lang) }}
31-
{{ if and $pretty (not (hasSuffix $dest "/")) }}
32-
{{ $dest = printf "%s/" $dest }}
33-
{{ end }}
34-
<li><a class="dropdown-item" href="{{ $dest }}" hreflang="{{ .Lang }}">{{ default .Lang .LanguageName }}</a></li>
34+
<li>
35+
{{- $state := cond (eq .Lang $lang) "active" "disabled" }}
36+
<a class="dropdown-item {{ $state }}" href="{{ cond (eq $state "active") $page.RelPermalink "#!" }}" hreflang="{{ .Lang }}">
37+
{{- cond $inline (upper .Lang) (default .Lang .LanguageName) -}}
38+
</a>
39+
</li>
3540
{{- end -}}
3641
{{- end -}}
3742
</ul>

0 commit comments

Comments
 (0)