Problem/Motivation

The module currently fails to generate the correct hierarchical structure for menus in the llms.txt file.

Instead of traversing the menu tree recursively, the module seems to be rendering items sequentially by depth/weight. This results in child items being visually appended to the last parent rendered of the previous level, rather than their actual parent.

Drupal menu:
Drupal menu

Llms.txt:
Llms.txt

Steps to reproduce

  1. Create a Main Menu structure with at least two parent items.
  2. Add a child item to the first parent item.
  3. Leave the second parent item without children.
  4. Generate/view the llms.txt file.
  5. Observe that the child of the first parent is rendered indented under the second parent.

Example scenario:

- Parent Item 1
  -- Child Item A
- Parent Item 2

Current output in llms.txt:

- [Parent Item 1](url)
- [Parent Item 2](url)
  - [Child Item A](url)  <-- INCORRECT: It appears as a child of Parent 2

Proposed resolution

The rendering logic needs to be refactored to traverse the menu tree properly.

Issue fork llms_txt-3567256

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

albeorte created an issue. See original summary.

albeorte’s picture

Issue summary: View changes
albeorte’s picture

Issue summary: View changes
albeorte’s picture

Issue summary: View changes

albeorte’s picture

Status: Active » Needs review
StatusFileSize
new7 KB

The changes have been implemented and tested.

Llms.txt fixed

Ready for review by the community.

mxr576’s picture

Status: Needs review » Needs work

Thanks for the issue, we will looking into it shortly. Meanwhile, could you please extend the module's test coverage to cover this issue?

mxr576’s picture

Status: Needs work » Needs review
mxr576’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

mxr576’s picture

Status: Fixed » Closed (fixed)