|
1 | 1 | <script lang="ts">
|
2 | 2 | import { page } from '$app/stores';
|
3 | 3 | import logo from './svelte-logo.svg';
|
| 4 | + import { l, localizedPaths, locale as currentLocale, defaultLocale } from '$lib/i18n'; |
| 5 | +
|
| 6 | + $: alternatePaths = $localizedPaths($page.url.pathname); |
| 7 | + $: defaultPath = alternatePaths[defaultLocale]; |
4 | 8 | </script>
|
5 | 9 |
|
| 10 | +<svelte:head> |
| 11 | + {#if defaultPath} |
| 12 | + <link rel="alternate" hreflang="x-default" href={defaultPath} /> |
| 13 | + {/if} |
| 14 | + {#each Object.entries(alternatePaths) as [locale, path]} |
| 15 | + <link rel="alternate" hreflang={locale} href={path} /> |
| 16 | + {/each} |
| 17 | +</svelte:head> |
| 18 | + |
6 | 19 | <header>
|
7 | 20 | <div class="corner">
|
8 | 21 | <a href="https://kit.svelte.dev">
|
|
15 | 28 | <path d="M0,0 L1,2 C1.5,3 1.5,3 2,3 L2,0 Z" />
|
16 | 29 | </svg>
|
17 | 30 | <ul>
|
18 |
| - <li class:active={$page.url.pathname === '/'}><a sveltekit:prefetch href="/">Home</a></li> |
19 |
| - <li class:active={$page.url.pathname === '/about'}> |
20 |
| - <a sveltekit:prefetch href="/about">About</a> |
| 31 | + <li class:active={$page.url.pathname === $l('/')}> |
| 32 | + <a sveltekit:prefetch href={$l('/')}>Home</a> |
| 33 | + </li> |
| 34 | + <li class:active={$page.url.pathname === $l('/about')}> |
| 35 | + <a sveltekit:prefetch href={$l('/about')}>About</a> |
21 | 36 | </li>
|
22 |
| - <li class:active={$page.url.pathname === '/todos'}> |
23 |
| - <a sveltekit:prefetch href="/todos">Todos</a> |
| 37 | + <li class:active={$page.url.pathname === $l('/todos')}> |
| 38 | + <a sveltekit:prefetch href={$l('/todos')}>Todos</a> |
24 | 39 | </li>
|
25 | 40 | </ul>
|
26 | 41 | <svg viewBox="0 0 2 3" aria-hidden="true">
|
|
30 | 45 |
|
31 | 46 | <div class="corner">
|
32 | 47 | <!-- TODO put something else here? github link? -->
|
| 48 | + <nav> |
| 49 | + {#each Object.entries(alternatePaths) as [locale, path]} |
| 50 | + <a class:active={$currentLocale === locale} href={path}>{locale}</a> |
| 51 | + {/each} |
| 52 | + </nav> |
33 | 53 | </div>
|
34 | 54 | </header>
|
35 | 55 |
|
|
40 | 60 | }
|
41 | 61 |
|
42 | 62 | .corner {
|
43 |
| - width: 3em; |
| 63 | + display: flex; |
44 | 64 | height: 3em;
|
45 | 65 | }
|
46 | 66 |
|
|
50 | 70 | justify-content: center;
|
51 | 71 | width: 100%;
|
52 | 72 | height: 100%;
|
| 73 | + text-transform: uppercase; |
| 74 | + } |
| 75 | +
|
| 76 | + .corner nav a { |
| 77 | + position: relative; |
| 78 | + } |
| 79 | +
|
| 80 | + .corner a.active::before { |
| 81 | + --size: 6px; |
| 82 | + content: ''; |
| 83 | + width: 0; |
| 84 | + height: 0; |
| 85 | + position: absolute; |
| 86 | + top: 0; |
| 87 | + left: calc(50% - var(--size)); |
| 88 | + border: var(--size) solid transparent; |
| 89 | + border-top: var(--size) solid var(--accent-color); |
53 | 90 | }
|
54 | 91 |
|
55 | 92 | .corner img {
|
|
0 commit comments