fix(blog): reduce list-to-post navigation lag
This commit is contained in:
@@ -94,7 +94,7 @@ const readMoreText = lang === 'zh' ? '阅读更多' : 'Read More';
|
|||||||
<div class="p-6 flex-1 flex flex-col justify-between">
|
<div class="p-6 flex-1 flex flex-col justify-between">
|
||||||
<div>
|
<div>
|
||||||
<h2 class="text-xl font-bold text-card-foreground mb-3 group-hover:text-primary transition-colors duration-200">
|
<h2 class="text-xl font-bold text-card-foreground mb-3 group-hover:text-primary transition-colors duration-200">
|
||||||
<a href={`${postBaseUrl}${post.slug}`}>
|
<a href={`${postBaseUrl}${post.slug}`} data-astro-reload>
|
||||||
{post.title}
|
{post.title}
|
||||||
</a>
|
</a>
|
||||||
</h2>
|
</h2>
|
||||||
@@ -137,6 +137,7 @@ const readMoreText = lang === 'zh' ? '阅读更多' : 'Read More';
|
|||||||
|
|
||||||
<a
|
<a
|
||||||
href={`${postBaseUrl}${post.slug}`}
|
href={`${postBaseUrl}${post.slug}`}
|
||||||
|
data-astro-reload
|
||||||
class="text-primary hover:text-primary font-medium flex items-center group"
|
class="text-primary hover:text-primary font-medium flex items-center group"
|
||||||
>
|
>
|
||||||
{readMoreText}
|
{readMoreText}
|
||||||
|
|||||||
@@ -13,12 +13,11 @@ export default function Comments({ lang = 'en', ...props }: CommentsProps) {
|
|||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const walineLang = lang === 'zh' ? 'zh-CN' : 'en';
|
const walineLang = lang === 'zh' ? 'zh-CN' : 'en';
|
||||||
|
const getTheme = () => (document.documentElement.classList.contains('dark') ? 'html.dark' : false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!containerRef.current) return;
|
if (!containerRef.current) return;
|
||||||
|
|
||||||
const getTheme = () => document.documentElement.classList.contains('dark') ? 'html.dark' : false;
|
|
||||||
|
|
||||||
const pathname = window.location.pathname;
|
const pathname = window.location.pathname;
|
||||||
const postsMatch = pathname.match(/\/posts\/([^/]+)/);
|
const postsMatch = pathname.match(/\/posts\/([^/]+)/);
|
||||||
const path = postsMatch ? postsMatch[1] : pathname;
|
const path = postsMatch ? postsMatch[1] : pathname;
|
||||||
@@ -34,18 +33,6 @@ export default function Comments({ lang = 'en', ...props }: CommentsProps) {
|
|||||||
path,
|
path,
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => walineInstanceRef.current?.destroy();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const getTheme = () => document.documentElement.classList.contains('dark') ? 'html.dark' : false;
|
|
||||||
|
|
||||||
walineInstanceRef.current?.update({
|
|
||||||
...props,
|
|
||||||
lang: walineLang,
|
|
||||||
dark: getTheme(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleThemeChange = () => {
|
const handleThemeChange = () => {
|
||||||
walineInstanceRef.current?.update({
|
walineInstanceRef.current?.update({
|
||||||
...props,
|
...props,
|
||||||
@@ -57,8 +44,22 @@ export default function Comments({ lang = 'en', ...props }: CommentsProps) {
|
|||||||
const observer = new MutationObserver(handleThemeChange);
|
const observer = new MutationObserver(handleThemeChange);
|
||||||
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
|
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
|
||||||
|
|
||||||
return () => observer.disconnect();
|
return () => {
|
||||||
}, [lang, props, walineLang]);
|
observer.disconnect();
|
||||||
|
const instance = walineInstanceRef.current;
|
||||||
|
walineInstanceRef.current = null;
|
||||||
|
|
||||||
|
if (instance) {
|
||||||
|
try {
|
||||||
|
instance.destroy();
|
||||||
|
} catch {
|
||||||
|
if (containerRef.current) {
|
||||||
|
containerRef.current.innerHTML = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [props, walineLang]);
|
||||||
|
|
||||||
return <div ref={containerRef} className="waline-container" />;
|
return <div ref={containerRef} className="waline-container" />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ const finalReadingTime = readTime ? parseInt(readTime.replace(/\D/g, '')) : unde
|
|||||||
|
|
||||||
<!-- Comments Section -->
|
<!-- Comments Section -->
|
||||||
<div class="mt-10 sm:mt-16 border-t border-border pt-10">
|
<div class="mt-10 sm:mt-16 border-t border-border pt-10">
|
||||||
<Comments client:only="react" lang={lang} />
|
<Comments client:visible lang={lang} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Author Card moved to bottom with enhanced styling -->
|
<!-- Author Card moved to bottom with enhanced styling -->
|
||||||
|
|||||||
Reference in New Issue
Block a user