Collect sidebar elements from modules

Assume a Hugo website that renders content from different repositories. The content is collected with Hugo modules, and each module defines a section with an _index.md.

I would like each module to define their own “section”/“folder” in a common sidebar, and I would like the entries to be fetched from the same repository as the content of the section.

What would be a good strategy to implement this with Hugo? Is that even possible?

I imagine a company website with multiple products and the following sidebar:

- Acme Corporation     -> main sidebar
  - Anvil              -> main sidebar
    - Setup            -> imported from acme/anvil.git
    - Usage            -> imported from acme/anvil.git
  - Glue               -> main sidebar
    - Setup            -> imported from acme/glue.git
    - Usage            -> imported from acme/glue.git

I would hope for some sidebar specification file in each module, that would then be imported into a point in the main sidebar.

If the main project does not have any other sections in its contentDir, range through the sections.

If the main project has other sections that you do not want to include in the sidebar, exclude those sections when building the sidebar page collection.