diff --git a/app/blog/[slug]/page.tsx b/app/blog/[slug]/page.tsx
index 25395fe..7e937b5 100644
--- a/app/blog/[slug]/page.tsx
+++ b/app/blog/[slug]/page.tsx
@@ -68,8 +68,8 @@ export default async function BlogPostPage({ params }: BlogPostPageProps) {
<>
{/* تصویر شاخص تمامعرض بالای صفحه */}
{thumbnailUrl && (
-
-
+
+
{
+ const { scrollY } = window;
+ const docHeight = document.documentElement.scrollHeight - window.innerHeight;
+ if (docHeight <= 0) {
+ setProgress(0);
+ return;
+ }
+ const value = Math.min(100, Math.max(0, (scrollY / docHeight) * 100));
+ setProgress(value);
+ }, []);
+
+ useEffect(() => {
+ update();
+ window.addEventListener("scroll", update, { passive: true });
+ window.addEventListener("resize", update);
+ return () => {
+ window.removeEventListener("scroll", update);
+ window.removeEventListener("resize", update);
+ };
+ }, [update]);
+
+ return progress;
+}
+
interface TocGroup {
heading: TocItem;
children: TocItem[];
@@ -54,6 +81,7 @@ export function BlogToc({ items, className }: BlogTocProps) {
const [activeId, setActiveId] = useState(items[0]?.id ?? null);
const [mobileOpen, setMobileOpen] = useState(false);
const [openSections, setOpenSections] = useState>(() => new Set());
+ const scrollProgress = useScrollProgress();
const groups = useMemo(() => groupByLevel2(items), [items]);
@@ -172,15 +200,25 @@ export function BlogToc({ items, className }: BlogTocProps) {
return (
<>
- {/* Desktop: sticky sidebar left */}
+ {/* Desktop: sticky sidebar with scroll progress bar */}
- {/* Mobile: collapsible, sticky when scrolling */}
+ {/* Mobile: collapsible with horizontal scroll progress bar */}
+
+ {/* Horizontal scroll progress indicator (mobile) */}
+
فهرست مطالب