Skip to content
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

Merged
merged 2 commits into from
Nov 15, 2024
Merged

Fix blogpost chapter nav #65

merged 2 commits into from
Nov 15, 2024

Conversation

rccsousa
Copy link
Collaborator

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

…on on page

refactors BlogpostChapters utilizing content_html once more. Refactors
getChapters to work properly with updated serialization
@rccsousa rccsousa marked this pull request as ready for review October 25, 2024 16:51
Copy link

netlify bot commented Oct 25, 2024

Deploy Preview for content-sub ready!

Name Link
🔨 Latest commit 02c217a
🔍 Latest deploy log https://app.netlify.com/sites/content-sub/deploys/671bcc718cd82e00086f4bc8
😎 Deploy Preview https://deploy-preview-65--content-sub.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +12 to +35
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]);
Copy link
Collaborator Author

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

@rccsousa rccsousa merged commit 04e5fba into main Nov 15, 2024
5 checks passed
@rccsousa rccsousa deleted the rs/fix-blogpost-chapter-nav branch November 15, 2024 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

create table of contents navigator for blogposts page
2 participants