Skip to content

Commit c33dabf

Browse files
authoredOct 26, 2020
header: add Language switch (#54)
* language-switch: init * header: move logo-switches together
1 parent a97de0f commit c33dabf

File tree

2 files changed

+75
-28
lines changed

2 files changed

+75
-28
lines changed
 

‎assets/css/header.css

+22-2
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
max-width: calc(var(--nav-width) + var(--gap) * 2);
88
margin-inline-start: auto;
99
margin-inline-end: auto;
10+
line-height: var(--header-height);
1011
}
1112

1213
.nav a {
1314
display: block;
14-
line-height: var(--header-height);
1515
}
1616

1717
.logo,
1818
.menu {
1919
display: flex;
2020
margin: auto var(--gap);
21+
flex-wrap: inherit;
2122
}
2223

2324
.logo a {
@@ -40,7 +41,7 @@
4041
user-select: none;
4142
}
4243

43-
body.dark #moon{
44+
body.dark #moon {
4445
vertical-align: middle;
4546
display: none;
4647
}
@@ -68,3 +69,22 @@ body:not(.dark) #sun {
6869
font-weight: 500;
6970
border-bottom: 2px solid currentColor;
7071
}
72+
73+
.lang-switch ul {
74+
display: inline-flex;
75+
}
76+
77+
.lang-switch a {
78+
font-size: 16px;
79+
font-weight: 500;
80+
margin: 0 8px;
81+
}
82+
83+
.lang-switch li {
84+
display: inline-flex;
85+
}
86+
87+
.logo-switches {
88+
display: inline-flex;
89+
flex-wrap: inherit;
90+
}

‎layouts/partials/header.html

+53-26
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
document.body.classList.add('dark');
1111
}
1212
}
13+
1314
</script>
1415
{{- end }}
1516
{{- if (and (.Site.Params.disableThemeToggle) (eq .Site.Params.defaultTheme "auto")) }}
1617
<script>
1718
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
1819
document.body.classList.add('dark');
1920
}
21+
2022
</script>
2123
{{- end }}
2224
<noscript>
@@ -25,43 +27,68 @@
2527
.top-link {
2628
display: none;
2729
}
30+
2831
</style>
2932
</noscript>
3033
<header class="header">
3134
<nav class="nav">
32-
<p class="logo">
35+
<div class="logo">
3336
<a href="{{ "" | absLangURL }}">
3437
{{- if .Site.Params.label.icon }}
3538
<img src="{{- .Site.Params.label.icon -}}" alt="logo" aria-label="logo"
3639
height="{{- .Site.Params.label.iconHeight | default "30px" -}}">
3740
{{- end -}}
3841
{{- .Site.Params.label.text | default .Site.Title -}}
3942
</a>
40-
{{- if (and (not .Site.Params.disableThemeToggle) (not (or (eq .Site.Params.defaultTheme "light") (eq .Site.Params.defaultTheme "dark")))) }}
41-
<span class="theme-toggle">
42-
<a id="theme-toggle">
43-
<svg id="moon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
44-
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
45-
stroke-linejoin="round">
46-
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path>
47-
</svg>
48-
<svg id="sun" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
49-
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
50-
stroke-linejoin="round">
51-
<circle cx="12" cy="12" r="5"></circle>
52-
<line x1="12" y1="1" x2="12" y2="3"></line>
53-
<line x1="12" y1="21" x2="12" y2="23"></line>
54-
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
55-
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
56-
<line x1="1" y1="12" x2="3" y2="12"></line>
57-
<line x1="21" y1="12" x2="23" y2="12"></line>
58-
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
59-
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
60-
</svg>
61-
</a>
43+
<span class="logo-switches">
44+
{{- if (and (not .Site.Params.disableThemeToggle) (not (or (eq .Site.Params.defaultTheme "light") (eq .Site.Params.defaultTheme "dark")))) }}
45+
<span class="theme-toggle">
46+
<a id="theme-toggle">
47+
<svg id="moon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
48+
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
49+
stroke-linejoin="round">
50+
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path>
51+
</svg>
52+
<svg id="sun" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
53+
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
54+
stroke-linejoin="round">
55+
<circle cx="12" cy="12" r="5"></circle>
56+
<line x1="12" y1="1" x2="12" y2="3"></line>
57+
<line x1="12" y1="21" x2="12" y2="23"></line>
58+
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
59+
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
60+
<line x1="1" y1="12" x2="3" y2="12"></line>
61+
<line x1="21" y1="12" x2="23" y2="12"></line>
62+
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
63+
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
64+
</svg>
65+
</a>
66+
</span>
67+
{{- end}}
68+
{{ $lang := .Lang}}
69+
{{- with $.Site.Home.AllTranslations }}
70+
<span class="lang-switch">
71+
<span>|</span>
72+
<ul>
73+
{{- range . -}}
74+
{{- if ne $lang .Lang }}
75+
<li>
76+
<a href="{{- .Permalink -}}" title="{{ .Language.LanguageName | default .Lang | humanize }}"
77+
aria-label="{{ .Language.LanguageName | default .Lang | humanize }}">
78+
{{- if (and $.Site.Params.displayFullLangName (.Language.LanguageName)) }}
79+
{{- .Language.LanguageName | humanize -}}
80+
{{- else }}
81+
{{- .Lang | humanize -}}
82+
{{- end -}}
83+
</a>
84+
</li>
85+
{{- end -}}
86+
{{- end}}
87+
</ul>
88+
</span>
89+
{{- end }}
6290
</span>
63-
{{- end}}
64-
</p>
91+
</div>
6592
{{- $currentPage := . }}
6693
<ul class="menu" id="menu" onscroll="menu_on_scroll()">
6794
{{- range .Site.Menus.main }}
@@ -75,7 +102,7 @@
75102
</span>
76103
</a>
77104
</li>
78-
{{- end }}
105+
{{- end -}}
79106
</ul>
80107
</nav>
81108
</header>

1 commit comments

Comments
 (1)

adityatelange commented on Oct 26, 2020

@adityatelange
OwnerAuthor

use

params.displayFullLangName: true to display languageName. By default key will be used

Please sign in to comment.