-
Notifications
You must be signed in to change notification settings - Fork 90
Fix TOC and section sync in BlogDetail, closes #290 #433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -62,34 +62,33 @@ const BlogDetail = () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ✅ Normalized content | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const content = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| toc: blog.content?.toc ?? [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Introduction", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Overview", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Key Points", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Analysis", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Conclusion", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| sections: blog.content?.sections ?? [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| heading: "Introduction", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| text: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| blog.excerpt || | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "This article provides insights into the latest cryptocurrency trends.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| heading: "Overview", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| text: "This article is currently being prepared with detailed analysis and insights.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Sections are the single source of truth for body + TOC (avoids toc/section count mismatches) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const sections = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| blog.content?.sections?.length > 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? blog.content.sections | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| : [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| heading: "Introduction", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| text: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| blog.excerpt || | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "This article provides insights into the latest cryptocurrency trends.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| heading: "Overview", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| text: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "This article is currently being prepared with detailed analysis and insights.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const scrollToSection = (index) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| document | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| .getElementById(`blog-section-${index}`) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+83
to
+85
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const scrollToSection = (index) => { | |
| document | |
| .getElementById(`blog-section-${index}`) | |
| // Create a deterministic, heading-based id for each section | |
| const createSectionId = (heading) => { | |
| if (!heading || typeof heading !== "string") { | |
| return "blog-section"; | |
| } | |
| const slug = heading | |
| .toLowerCase() | |
| .trim() | |
| .replace(/[^a-z0-9]+/g, "-") | |
| .replace(/^-+|-+$/g, ""); | |
| return `blog-section-${slug || "section"}`; | |
| }; | |
| const sectionIds = sections.map((section) => createSectionId(section.heading)); | |
| const scrollToSection = (index) => { | |
| const sectionId = sectionIds[index]; | |
| if (!sectionId) { | |
| return; | |
| } | |
| document | |
| .getElementById(sectionId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scroll-margin-top: 100pxduplicates thetop: 100pxoffset used for the sticky sidebar. To avoid these drifting out of sync when the header/sticky offset changes, consider extracting this value into a single CSS custom property and reusing it in both places.