From 96696a63840662f69d87fa4651816e9f6ae821f8 Mon Sep 17 00:00:00 2001 From: fkakatie Date: Mon, 13 Jul 2026 13:17:13 -0600 Subject: [PATCH] fix: decode uri for french --- blocks/jump-nav/jump-nav.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/blocks/jump-nav/jump-nav.js b/blocks/jump-nav/jump-nav.js index 05ae32d..852bbae 100644 --- a/blocks/jump-nav/jump-nav.js +++ b/blocks/jump-nav/jump-nav.js @@ -1,5 +1,14 @@ import { loadCopy } from '../../scripts/scripts.js'; +/** + * Gets the decoded fragment id a jump-nav link points to. + * @param {HTMLAnchorElement} a Jump-nav link + * @returns {string} Decoded target id + */ +function getId(a) { + return decodeURIComponent(new URL(a.href).hash.slice(1)); +} + export default async function decorate(block) { const copy = await loadCopy(import.meta.url); const ul = block.querySelector('ul'); @@ -20,7 +29,7 @@ export default async function decorate(block) { const targets = links .map((a) => { try { - return document.getElementById(new URL(a.href).hash.slice(1)); + return document.getElementById(getId(a)); } catch { return null; } @@ -35,22 +44,22 @@ export default async function decorate(block) { }); resizeObserver.observe(container); - const hash = window.location.hash.slice(1); - const initial = (hash && links.find((a) => a.href.endsWith(`#${hash}`))) || links[0]; + const hash = decodeURIComponent(window.location.hash.slice(1)); + const initial = (hash && links.find((a) => getId(a) === hash)) || links[0]; if (initial) initial.setAttribute('aria-current', 'location'); const prefersReduced = () => window.matchMedia('(prefers-reduced-motion: reduce)').matches; links.forEach((a) => { a.addEventListener('click', (e) => { - const id = new URL(a.href).hash.slice(1); + const id = getId(a); const target = document.getElementById(id); if (!target) return; e.preventDefault(); const behavior = prefersReduced() ? 'auto' : 'smooth'; target.scrollIntoView({ behavior }); a.scrollIntoView({ behavior, inline: 'center', block: 'nearest' }); - window.history.pushState(null, '', `#${id}`); + window.history.pushState(null, '', `#${encodeURIComponent(id)}`); }); }); @@ -65,7 +74,7 @@ export default async function decorate(block) { .sort((a, b) => b.px - a.px)[0]; if (!mostVisible) return; - const active = links.find((a) => a.href.endsWith(`#${mostVisible.t.id}`)); + const active = links.find((a) => getId(a) === mostVisible.t.id); if (!active) return; links.forEach((a) => a.removeAttribute('aria-current'));