Riverscapes / riverscapes-gatsby-theme

The theme for all Gatsby Riverscapes sites
https://riverscapes.github.io/riverscapes-gatsby-theme/
1 stars 1 forks source link

Add a nested menu to list all MDX pages #20

Closed hazuremon closed 3 months ago

hazuremon commented 4 months ago

@MattReimer Based on our discussions, I am pulling in all pages MDX files as defined in gatsby-config.js and using their information for the side menu. Please test and verify if the setup is as intended.


Summary

This pull request introduces a new AllPagesMenu component, which dynamically generates a nested navigation menu based on a provided list of MDX nodes. The component processes the page nodes, which include titles and slugs from the MDX frontmatter, to group them by slug levels and output a structured navigation menu.

Changes

Implementation Details

  1. Grouping Logic:
    • groupItemsBySlugLevels(entries): Iterates through the page nodes to group them by their slug levels.
    • Constructs a nested object where each level corresponds to a part of the slug path.
    • Each entry at the final slug level includes the url and title.
  2. Conversion to Menu Structure:
    • convertToStructure(entries): Converts the grouped object into an array format suitable for rendering by the SideNav component.
    • Ensures that each item contains title, url, and items properties.
  3. Rendering:
    • The AllPagesMenu component renders a nav element containing the SideNav component.
    • Passes the structured navigation data and heading configuration to SideNav.