|
1 | 1 | <script lang="ts"> |
2 | 2 | import { browser } from '$app/environment' |
3 | | - import { afterNavigate } from '$app/navigation' |
| 3 | + import { afterNavigate, goto } from '$app/navigation' |
| 4 | + import { resolve } from '$app/paths' |
4 | 5 | import Footer from '$lib/components/footer.svelte' |
5 | 6 | import MinecraftIcon from '$lib/components/minecraftIcon.svelte' |
6 | | - import { onDestroy, onMount, tick } from 'svelte' |
| 7 | + import { DEFAULT_LANGUAGE, docHref } from '$lib/docs/docs' |
| 8 | + import { onDestroy, onMount, setContext, tick } from 'svelte' |
7 | 9 |
|
8 | 10 | interface TocHeading { |
9 | 11 | id: string |
|
17 | 19 | const defaultDescription = 'Effortlessly craft complex animations for Minecraft: Java Edition' |
18 | 20 | const socialImage = `${siteUrl}/images/animated_java_icon.svg` |
19 | 21 |
|
| 22 | + const lang = $derived(data.params.lang ?? DEFAULT_LANGUAGE) |
| 23 | + $effect(() => { |
| 24 | + setContext('lang', lang) |
| 25 | + console.log(`Current language set to: ${lang}`) |
| 26 | + }) |
| 27 | +
|
| 28 | + function handleClick(event: MouseEvent): void { |
| 29 | + const target = (event.target as HTMLElement).closest('a') |
| 30 | + if (!target) return |
| 31 | + const path = target.getAttribute('data-doc-link') |
| 32 | + if (!path) return |
| 33 | +
|
| 34 | + event.preventDefault() |
| 35 | + const prefix = lang === DEFAULT_LANGUAGE ? '' : `/${lang}` |
| 36 | + void goto(resolve(`${prefix}/docs/${path}`)) |
| 37 | + } |
| 38 | +
|
20 | 39 | const pageTitle = $derived( |
21 | 40 | data.currentDoc?.title ? `${data.currentDoc.title} | ${docsTitle}` : docsTitle |
22 | 41 | ) |
|
201 | 220 | <meta name="twitter:image" content={socialImage} /> |
202 | 221 | </svelte:head> |
203 | 222 |
|
| 223 | +<svelte:window onclick={handleClick} /> |
| 224 | + |
204 | 225 | <div class="docs-shell"> |
205 | 226 | <header class="docs-header minecraft-box"> |
206 | 227 | <a href="/" class="brand-link"> |
|
265 | 286 | <a |
266 | 287 | class={`section-link ${data.currentPath === section.to ? 'active' : ''}`} |
267 | 288 | onclick={closeMobileSidebar} |
268 | | - href={section.to} |
| 289 | + href={docHref(section.to, lang)} |
269 | 290 | >{section.title} |
270 | 291 |
|
271 | 292 | {#if data.currentPath === section.to} |
|
283 | 304 | <a |
284 | 305 | class:active={data.currentPath === item.to} |
285 | 306 | onclick={closeMobileSidebar} |
286 | | - href={item.to} |
| 307 | + href={docHref(item.to, lang)} |
287 | 308 | >{item.title} |
288 | 309 |
|
289 | 310 | {#if data.currentPath === item.to} |
|
307 | 328 | {#if data.previous ?? data.next} |
308 | 329 | <nav class="docs-pagination" aria-label="Previous and next page links"> |
309 | 330 | {#if data.previous} |
310 | | - <a class="minecraft-button" href={data.previous.to} |
| 331 | + <a class="minecraft-button" href={docHref(data.previous.to, lang)} |
311 | 332 | >← {data.previous.title}</a |
312 | 333 | > |
313 | 334 | {:else} |
314 | 335 | <div></div> |
315 | 336 | {/if} |
316 | 337 |
|
317 | 338 | {#if data.next} |
318 | | - <a class="minecraft-button" href={data.next.to}>{data.next.title} →</a> |
| 339 | + <a class="minecraft-button" href={docHref(data.next.to, lang)} |
| 340 | + >{data.next.title} →</a |
| 341 | + > |
319 | 342 | {/if} |
320 | 343 | </nav> |
321 | 344 | {/if} |
|
0 commit comments