From 0d1319e03ff51df7598096ff9da9877ca963b1f8 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Wed, 7 Jan 2026 13:04:01 +0800 Subject: [PATCH 1/3] feat: sidebar active link scroll into view --- src/generators/web/bootstrap.js | 30 ++++++++++++++++++++++++++++++ src/generators/web/template.html | 1 + 2 files changed, 31 insertions(+) create mode 100644 src/generators/web/bootstrap.js diff --git a/src/generators/web/bootstrap.js b/src/generators/web/bootstrap.js new file mode 100644 index 00000000..d79d7941 --- /dev/null +++ b/src/generators/web/bootstrap.js @@ -0,0 +1,30 @@ +'use strict'; + +{ + function setupSidebarScroll() { + // eslint-disable-next-line no-undef + const sidebarLinks = document.querySelectorAll('aside > section > ul > a'); + + let link; + for (link of sidebarLinks) { + // eslint-disable-next-line no-undef + if (link.pathname === window.location.pathname) break; + } + + if (!link) return; + + link.scrollIntoView({ behavior: 'smooth', block: 'center' }); + } + + function bootstrap() { + setupSidebarScroll(); + } + + // eslint-disable-next-line no-undef + if (document.readyState === 'loading') { + // eslint-disable-next-line no-undef + document.addEventListener('DOMContentLoaded', bootstrap, { once: true }); + } else { + bootstrap(); + } +} diff --git a/src/generators/web/template.html b/src/generators/web/template.html index fa59fb8e..fe323e7a 100644 --- a/src/generators/web/template.html +++ b/src/generators/web/template.html @@ -22,6 +22,7 @@ +
From 297b9df1c96857b6f044523bc13c88d05005041c Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Wed, 7 Jan 2026 13:11:21 +0800 Subject: [PATCH 2/3] fix: update --- src/generators/web/template.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generators/web/template.html b/src/generators/web/template.html index fe323e7a..2714ec73 100644 --- a/src/generators/web/template.html +++ b/src/generators/web/template.html @@ -22,7 +22,7 @@ - + From a4edfbc1d59fb0d40e045e7edfa97f782c4659cf Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Wed, 7 Jan 2026 13:17:58 +0800 Subject: [PATCH 3/3] fix: update --- src/generators/web/bootstrap.js | 30 ------------------------------ src/generators/web/template.html | 27 ++++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 31 deletions(-) delete mode 100644 src/generators/web/bootstrap.js diff --git a/src/generators/web/bootstrap.js b/src/generators/web/bootstrap.js deleted file mode 100644 index d79d7941..00000000 --- a/src/generators/web/bootstrap.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; - -{ - function setupSidebarScroll() { - // eslint-disable-next-line no-undef - const sidebarLinks = document.querySelectorAll('aside > section > ul > a'); - - let link; - for (link of sidebarLinks) { - // eslint-disable-next-line no-undef - if (link.pathname === window.location.pathname) break; - } - - if (!link) return; - - link.scrollIntoView({ behavior: 'smooth', block: 'center' }); - } - - function bootstrap() { - setupSidebarScroll(); - } - - // eslint-disable-next-line no-undef - if (document.readyState === 'loading') { - // eslint-disable-next-line no-undef - document.addEventListener('DOMContentLoaded', bootstrap, { once: true }); - } else { - bootstrap(); - } -} diff --git a/src/generators/web/template.html b/src/generators/web/template.html index 2714ec73..7c61efea 100644 --- a/src/generators/web/template.html +++ b/src/generators/web/template.html @@ -22,7 +22,32 @@ - +