|
1 | 1 | ---
|
2 |
| -import { languages } from '../i18n/ui'; |
3 | 2 | import { base } from "astro:config/client"
|
4 | 3 |
|
| 4 | +const languages = Object.keys(import.meta.glob('../pages/*.astro')).map(p=>p.split("/").at(-1).replace(".astro", "")).sort(); |
5 | 5 | const pathname = Astro.url.pathname.replace(import.meta.env.BASE_URL, "");
|
| 6 | +const currentLang = pathname.split("/")[1]; |
6 | 7 | ---
|
7 |
| -<ul class="language-picker"> |
8 |
| - {Object.entries(languages).sort((a, b) => a < b ? 0 : -1).map(([lang, label]) => ( |
9 |
| - <li class:list= {[{ active: pathname.startsWith(`/${label}`) }]} > |
10 |
| - <a href={`${base}/${lang}/`}>{label}</a> |
11 |
| - </li> |
| 8 | +<div class="language-switcher"> |
| 9 | + {languages.map((lang, i) => ( |
| 10 | + <> |
| 11 | + <a href={`${base}/${lang}/`} class:list={{active: lang === currentLang}}> |
| 12 | + {lang.toUpperCase()} |
| 13 | + </a> |
| 14 | + {i < languages.length - 1 && <span class="separator">/</span>} |
| 15 | + </> |
12 | 16 | ))}
|
13 |
| -</ul> |
| 17 | +</div> |
14 | 18 |
|
15 | 19 | <style>
|
16 |
| -ul { |
17 |
| - list-style: none; |
18 |
| - padding: 0; |
19 |
| - margin: 0; |
20 |
| - display: flex; |
21 |
| - justify-content: flex-end; |
22 |
| - margin-right: 1rem; |
23 |
| - |
24 |
| - a { |
25 |
| - text-decoration: none; |
26 |
| - } |
| 20 | +.language-switcher { |
| 21 | + position: absolute; |
| 22 | + top: 1rem; |
| 23 | + right: 1rem; |
| 24 | + font-size: 1.5rem; |
| 25 | + font-weight: 500; |
| 26 | +} |
27 | 27 |
|
| 28 | +.language-switcher a { |
| 29 | + color: rgba(255, 255, 255, 0.7); |
| 30 | + text-decoration: none; |
| 31 | + transition: color 0.2s ease; |
28 | 32 | }
|
29 | 33 |
|
30 |
| -li:first-child::after { |
31 |
| - content: '/'; |
32 |
| - display: 'inline block' |
33 |
| - margin: 0 8px; |
34 |
| - color: #333; |
| 34 | +.language-switcher a:hover { |
| 35 | + color: #ffffff; |
| 36 | + text-decoration: underline; |
| 37 | +} |
35 | 38 |
|
| 39 | +.language-switcher .separator { |
| 40 | + color: rgba(255, 255, 255, 0.5); |
| 41 | + margin: 0 0.3rem; |
36 | 42 | }
|
37 | 43 |
|
38 |
| -li.active > a { |
39 |
| - font-weight: bold; |
40 |
| - text-decoration: underline; |
| 44 | +/* Active language style */ |
| 45 | +.language-switcher a.active { |
| 46 | + color: #ffffff; |
| 47 | + font-weight: 600; |
41 | 48 | }
|
42 | 49 | </style>
|
0 commit comments