Add auto-generated table of contents to blog posts - #13881
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces an automatically generated table of contents for blog posts. It adds a new BlogTableOfContents component, registers the TableOfContentsExtension on the server, integrates the component into the blog layout, and adds the corresponding SCSS styles. The review feedback suggests improving type safety in the new component by replacing a direct cast with an is check, and updating the SCSS selectors to ensure the material icon classes are correctly targeted for transition and rotation effects.
|
/gcbrun |
|
Staged preview of the updated docs.flutter.dev site (updated for commit fa70ca5): https://flutter-docs-prod--docs-pr13881-blog-toc-lhiqdejt.web.app |
|
Staged preview of the updated flutter.dev site (updated for commit fa70ca5): https://flutter-dev-230821--www-pr13881-blog-toc-w4ju31lj.web.app |
- Add BlogTableOfContents, built on jaspr_content's built-in TableOfContentsExtension, showing a collapsible "On this page" nav for posts with at least 2 top-level headings. - Fix scroll-margin-top for heading anchors on www, which was silently a no-op because --site-header-height/--site-subheader-height were never defined for this site.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Adds a table of contents to long-form blog posts, to make navigating them easier.
BlogTableOfContents(packages/site_shared/lib/components/blog/blog_toc.dart), which renders an automatically generated, collapsible "On this page" nav from the post's rendered headings. It's built onjaspr_content's existingTableOfContentsExtensionrather than a custom implementation, so it correctly builds anchor links relative to the current page path. Posts with fewer than 2 top-level headings don't show a TOC.flutter.dev(for example, TOC links, or#some-headingURLs) were landing behind the fixed header instead of scrolling clear of it. The existingscroll-margin-toprule in_content.scssreferenced--site-header-height/--site-subheader-height, which are defined fordocs.flutter.devbut were never defined for this site, silently making the rule a no-op. Defines them, aliased to the existing--ui-header-heightvariable.Fixes #13737
Requested to split from #13870