From 1bcf3235b6421c8a9a0cdfaa0ec0dfe6c02b0ddd Mon Sep 17 00:00:00 2001 From: nym21 Date: Wed, 3 Jun 2026 16:37:00 +0200 Subject: [PATCH] website: redesign part 4 --- website/build/style.css | 2 -- website/explore/style.css | 2 -- website/home/style.css | 2 -- website/learn/index.js | 26 +++++++++++++------------- website/learn/style.css | 7 +------ website/styles/main.css | 11 +++-------- 6 files changed, 17 insertions(+), 33 deletions(-) diff --git a/website/build/style.css b/website/build/style.css index 29b0c2efe..60c614713 100644 --- a/website/build/style.css +++ b/website/build/style.css @@ -1,7 +1,5 @@ main.build { - min-height: 100dvh; display: grid; place-items: center; - color: white; font-size: 4rem; } diff --git a/website/explore/style.css b/website/explore/style.css index 05aa37400..a7c94fc76 100644 --- a/website/explore/style.css +++ b/website/explore/style.css @@ -1,7 +1,5 @@ main.explore { - min-height: 100dvh; display: grid; place-items: center; - color: white; font-size: 4rem; } diff --git a/website/home/style.css b/website/home/style.css index 50014ee21..54bde0219 100644 --- a/website/home/style.css +++ b/website/home/style.css @@ -1,7 +1,5 @@ main.home { - min-height: 100dvh; display: grid; place-items: center; - color: white; font-size: 4rem; } diff --git a/website/learn/index.js b/website/learn/index.js index ddb7cb05c..213418fec 100644 --- a/website/learn/index.js +++ b/website/learn/index.js @@ -15,10 +15,9 @@ function createChart(label) { /** * @param {string} title - * @param {number[]} indexes */ -function createSectionId(title, indexes) { - return `${indexes.join("-")}-${title.toLowerCase().replaceAll(" ", "-")}`; +function createSectionId(title) { + return title.toLowerCase().replaceAll(" ", "-"); } /** @@ -30,9 +29,10 @@ function createSection(section, indexes) { const title = document.createElement(indexes.length === 1 ? "h1" : "h2"); const anchor = document.createElement("a"); const description = document.createElement("p"); + const id = createSectionId(section.title); - element.id = createSectionId(section.title, indexes); - anchor.href = `#${element.id}`; + title.id = id; + anchor.href = `#${id}`; anchor.append(section.title); title.append(anchor); description.append(section.description); @@ -52,7 +52,7 @@ function createSection(section, indexes) { function createContentsItem(section, indexes) { const item = document.createElement("li"); const anchor = document.createElement("a"); - anchor.href = `#${createSectionId(section.title, indexes)}`; + anchor.href = `#${createSectionId(section.title)}`; anchor.append(section.title); item.append(anchor); @@ -83,7 +83,7 @@ function createContents() { /** @param {HTMLElement} main */ function initScrollSpy(main) { - const sections = [...main.querySelectorAll("section[id]")]; + const titles = [...main.querySelectorAll("h1[id], h2[id]")]; const visible = new Set(); const links = new Map( [...main.querySelectorAll('nav a[href^="#"]')].map((link) => [ @@ -96,15 +96,15 @@ function initScrollSpy(main) { let current = null; function update() { - const section = sections.find((section) => visible.has(section.id)); - if (!section) return; + const title = titles.find((title) => visible.has(title.id)); + if (!title) return; - const hash = `#${section.id}`; + const hash = `#${title.id}`; if (hash === current) return; links.get(current)?.removeAttribute("aria-current"); links.get(hash)?.setAttribute("aria-current", "location"); - history.replaceState(null, "", `/learn${hash}`); + history.replaceState(null, "", hash); current = hash; } @@ -119,8 +119,8 @@ function initScrollSpy(main) { update(); }); - for (const section of sections) { - observer.observe(section); + for (const title of titles) { + observer.observe(title); } } diff --git a/website/learn/style.css b/website/learn/style.css index 861f4681b..12536a6ea 100644 --- a/website/learn/style.css +++ b/website/learn/style.css @@ -1,19 +1,13 @@ main.learn { - min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr) 14rem; gap: 4rem; padding: 8rem 2rem 6rem; - color: white; article { width: min(100%, 52rem); justify-self: center; - section { - scroll-margin-top: 6rem; - } - > section + section { margin-top: 8rem; } @@ -27,6 +21,7 @@ main.learn { h2 { font-weight: 400; line-height: 1; + scroll-margin-top: 6rem; a { position: relative; diff --git a/website/styles/main.css b/website/styles/main.css index 89ce1f676..49f05dee6 100644 --- a/website/styles/main.css +++ b/website/styles/main.css @@ -12,8 +12,10 @@ body { position: fixed; inset: 0; overflow: auto; + color: white; opacity: 0; pointer-events: none; + scroll-behavior: smooth; transition: opacity 180ms ease; } @@ -23,16 +25,9 @@ body { } } -html { - scroll-behavior: smooth; -} - @media (prefers-reduced-motion: reduce) { body > main { + scroll-behavior: auto; transition: none; } - - html { - scroll-behavior: auto; - } }