mirror of
https://github.com/zenlm/zen-blog.git
synced 2026-07-27 03:09:00 +00:00
- Replace Hugo static site generator with Next.js 15 + fumadocs-mdx - Convert 71 blog posts from Hugo format to MDX/MD - Convert Hugo shortcodes (figure, button, video, example, fullwidth) to MDX components (Figure, LinkButton, Video, Fullwidth) - Add remark-math + rehype-katex for LaTeX math rendering - Copy JSON case files to public/cases/ for reference - Update branding for Zen LM (site-nav, footer, metadata) - Static export for Cloudflare Pages deployment - Chinese (.zh.md) translations deferred for future migration
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
|
|
export function HashScrollHandler() {
|
|
useEffect(() => {
|
|
const handleHashScroll = () => {
|
|
const hash = window.location.hash;
|
|
if (hash) {
|
|
const element = document.getElementById(hash.slice(1));
|
|
if (element) {
|
|
const offset = 80;
|
|
const elementPosition = element.getBoundingClientRect().top;
|
|
const offsetPosition = elementPosition + window.pageYOffset - offset;
|
|
window.scrollTo({
|
|
top: offsetPosition,
|
|
behavior: 'smooth'
|
|
});
|
|
}
|
|
}
|
|
};
|
|
if (window.location.hash) {
|
|
setTimeout(handleHashScroll, 100);
|
|
}
|
|
window.addEventListener('hashchange', handleHashScroll);
|
|
|
|
return () => {
|
|
window.removeEventListener('hashchange', handleHashScroll);
|
|
};
|
|
}, []);
|
|
|
|
return null;
|
|
}
|