diff --git a/src/views/Portfolio.svelte b/src/views/Portfolio.svelte index a23a142..9510344 100644 --- a/src/views/Portfolio.svelte +++ b/src/views/Portfolio.svelte @@ -11,10 +11,30 @@ let sectionEl = $state(null) // --- Derived --- - const isActive = $derived(slides.active?.id === 'portfolio') - const projects = $derived(data?.projects ?? []) + const isActive = $derived(slides.active?.id === 'portfolio') + const projects = $derived(data?.projects ?? []) const currentProject = $derived(projects[currentIndex] ?? null) + // --- Ancres --- + function setAnchor(index) { + const slug = projects[index]?.slug + if (!slug) return + history.replaceState(null, '', '#' + slug) + } + + function clearAnchor() { + history.replaceState(null, '', window.location.pathname + window.location.search) + } + + // Initialisation depuis l'ancre URL — une seule fois quand projects est prêt + $effect(() => { + if (projects.length === 0) return + const hash = window.location.hash.slice(1) + if (!hash) return + const idx = projects.findIndex(p => p.slug === hash) + if (idx > 0) currentIndex = idx + }) + // --- Scroll nav composable --- const nav = createScrollNav({ isActive: () => isActive, @@ -24,6 +44,7 @@ : Math.max(currentIndex - 1, 0) if (next === currentIndex) return false currentIndex = next + setAnchor(next) }, }) @@ -44,6 +65,7 @@ if (!isActive) { nav.reset() currentIndex = 0 + clearAnchor() } }) @@ -97,7 +119,7 @@