-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fix blogpost chapter nav #65
Conversation
…on on page refactors BlogpostChapters utilizing content_html once more. Refactors getChapters to work properly with updated serialization
✅ Deploy Preview for content-sub ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
useEffect(() => { | ||
const headings = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); | ||
|
||
extractHeadings(); | ||
const observer = new IntersectionObserver((entries) => { | ||
let visibleId = ""; | ||
|
||
entries.forEach((entry) => { | ||
if (entry.isIntersecting || entry.boundingClientRect.bottom < 0) { | ||
visibleId = entry.target.id; | ||
} | ||
}); | ||
|
||
}, []); | ||
setVisibleChapter(visibleId); | ||
}, { | ||
root: null, | ||
threshold: 0.5, | ||
}); | ||
|
||
headings.forEach((heading) => observer.observe(heading)); | ||
|
||
return () => { | ||
headings.forEach((heading) => observer.unobserve(heading)); | ||
}; | ||
}, [chapters]); |
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.
@davelange regarding blogpost chapter nav, IntersectionObserver seems a bit finicky
links are working fine, but the navbar is not working spectacularly. when there is more than 1 id on the viewport" it makes sense, but when there is only one it sometimes work and sometimes doesn't
couldn't find a better way to achieve this result, is there a better way to achieve this result?
demo of the behavior: https://github.com/user-attachments/assets/6c47308a-710a-4103-9a1b-ddc25baf9155
Why
With the update to Payload 3.0 and switching to using serialized Lexical nodes instead of
content_html
, blogpost chapter navigation was broken, not allowing to navigate and just displaying different chapter titltes.How
By reimplementing chapter navigation using
content_html
and updating Lexical node serialization to include chapter ids on headings.Closes #25