feat: enhance SSR support with language extraction, dynamic page titles, and updated styles; adjust color theme

This commit is contained in:
2026-02-26 11:09:42 +00:00
parent 40ffa8207e
commit 965a505e15
8 changed files with 85 additions and 37 deletions

View File

@@ -1,5 +1,6 @@
import { addMessages, init } from "svelte-i18n"
import { DEFAULT_LANGUAGE } from "./lib/i18n"
import { render } from "svelte/server"
import { addMessages, init, locale } from "svelte-i18n"
import { DEFAULT_LANGUAGE, extractLanguageFromPath } from "./lib/i18n"
import deLocale from "./lib/i18n/locales/de.json"
import enLocale from "./lib/i18n/locales/en.json"
import App from "./App.svelte"
@@ -8,9 +9,30 @@ import App from "./App.svelte"
addMessages("de", deLocale)
addMessages("en", enLocale)
init({
fallbackLocale: DEFAULT_LANGUAGE,
initialLocale: DEFAULT_LANGUAGE,
})
/**
* SSR render wrapper for Svelte 5.
*
* tibi-server calls `app.default.render({ url })`.
* Svelte 5 no longer provides a `.render()` method on components —
* instead `render()` must be imported from `svelte/server`.
*
* This wrapper keeps the hook-side API compatible while delegating
* to the Svelte 5 render function internally.
*/
export default {
render({ url }: { url: string }) {
const lang = extractLanguageFromPath(url) || DEFAULT_LANGUAGE
export default App
init({
fallbackLocale: DEFAULT_LANGUAGE,
initialLocale: lang,
})
locale.set(lang)
const { body, head } = render(App, {
props: { url },
})
return { html: body, head }
},
}