Files
dezky/apps/website/composables/useLanding.ts
T
Ronni Baslund 7bee161ac1 feat(website): bilingual i18n (English default, Danish at /da) + SEO
Add @nuxtjs/i18n: English is the default locale (no prefix), Danish lives
under /da (prefix_except_default). Both server-rendered and indexed with
hreflang alternates + per-locale canonical (useLocaleHead in app.vue).
First-visit browser language is auto-detected and remembered in the
i18n_redirected cookie (redirectOn root).

- Keep the hand-authored COPY object; useLang/useCopy now read the i18n
  locale; useLocalizeHref/useLangToggle added. Every internal link is
  localized so navigation stays in-locale.
- Clear segmented EN|DA language switcher (active segment filled) replacing
  the ambiguous "en · da" pill.
- SEO: useSeoMeta defaults are locale-aware; og:image switches per locale
  (English / Danish share card); favicon links; robots.txt + sitemap.xml;
  env-aware siteUrl/baseUrl (localhost in dev, dezky.eu in prod).
- Update the cookie policy (dezky-lang -> i18n_redirected).
- Gate the Traefik wss:443 HMR behind DEZKY_TRAEFIK so localhost dev/DevTools
  connect over plain ws (fixes the DevTools disconnect loop).
2026-06-06 20:46:26 +02:00

58 lines
2.2 KiB
TypeScript

import { computed } from 'vue'
import { COPY, type Lang } from '~/utils/landingCopy'
import { makeTheme } from '~/utils/landingTokens'
// Locale is owned by @nuxtjs/i18n (URL-based: English at /, Danish at /da, with
// cookie-remembered browser detection). useLang exposes it as the 'da' | 'en'
// the COPY object expects; useCopy maps to the matching translations. `dark` is
// unused machinery from the design's Tweaks panel (the site is light-only).
export const useLang = () => {
const { locale } = useI18n()
return computed<Lang>(() => (locale.value === 'da' ? 'da' : 'en'))
}
export const useDark = () => useState<boolean>('dz-dark', () => false)
export const useTheme = () => {
const dark = useDark()
return computed(() => makeTheme(dark.value))
}
export const useCopy = () => {
const { locale } = useI18n()
return computed(() => COPY[locale.value === 'da' ? 'da' : 'en'])
}
// Setup-only. Returns a click handler that switches to the other locale's
// localized route (flips the URL, e.g. / <-> /da).
export function useLangToggle() {
const { locale } = useI18n()
const switchLocalePath = useSwitchLocalePath()
return () => navigateTo(switchLocalePath(locale.value === 'da' ? 'en' : 'da'))
}
// Setup-only. Localizes an internal href, preserving any #hash. Page links get
// the locale prefix (/about -> /da/about in Danish); section anchors resolve
// against the current locale's home (/#suite -> /da#suite). Bare #hash returns
// unchanged (same-page anchor).
export function useLocalizeHref() {
const localePath = useLocalePath()
return (href: string) => {
if (href.startsWith('#')) return href
const i = href.indexOf('#')
const path = i === -1 ? href : href.slice(0, i)
const hash = i === -1 ? '' : href.slice(i)
return localePath(path || '/') + hash
}
}
// Smooth-scroll to an in-page anchor, accounting for the sticky 72px nav.
// Non-anchor / placeholder links (#) are ignored.
export function scrollToAnchor(hash: string) {
if (!hash || hash === '#' || !hash.startsWith('#')) return
const el = document.getElementById(hash.slice(1))
if (!el) return
const top = el.getBoundingClientRect().top + window.scrollY - 72
window.scrollTo({ top, behavior: 'smooth' })
history.replaceState(null, '', hash)
}