Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions automation/source-repo-templates/api-docs.typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -453,34 +453,53 @@ jobs:

tree: dict = {}

def insert(node, parts, full_id):
def insert_file(node, parts, full_id):
if len(parts) == 1:
node.setdefault("_files", []).append((parts[0], full_id))
return
head, *rest = parts
insert(node.setdefault("_dirs", {}).setdefault(head, {}), rest, full_id)
insert_file(
node.setdefault("_dirs", {}).setdefault(head, {}),
rest,
full_id,
)
Comment on lines +456 to +465
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The insert_file function (renamed from insert) uses recursion, whereas the new insert_landing function is iterative. Switching to an iterative approach here would improve consistency and is generally safer for deep directory structures, avoiding potential recursion depth limits.

          def insert_file(node, parts, full_id):
              cur = node
              for i in range(len(parts) - 1):
                  cur = cur.setdefault("_dirs", {}).setdefault(parts[i], {})
              cur.setdefault("_files", []).append((parts[-1], full_id))


def insert_landing(node, parts, full_id):
# Drill down to the dir node for `parts` and store the
# landing page id there. Stored on the dir itself rather
# than as a sibling _files leaf so the directory and its
# landing aren't both rendered in the parent group
# (which produced the duplicate-entries bug we hit on
# multi-package nav: each package showed up once as a
# standalone page and once as a collapsible group).
cur = node
for part in parts:
cur = cur.setdefault("_dirs", {}).setdefault(part, {})
cur["_landing"] = full_id

for p in raw:
if p in ("README", "index"):
continue
# Each subdir's landing page is `<dir>/index.md` (after
# the rename step above) which Mintlify natively
# resolves from page id `<dir>`. Strip the `/index`
# suffix when building the registered path so the URL
# stays clean (`/<dir>` not `/<dir>/index`). Same
# principle applied to legacy `/README` entries in
# case any downstream tool still emits them.
# resolves from page id `<dir>`. Register it as the
# landing of that dir's group so the URL stays clean
# (`/<dir>` not `/<dir>/index`) and the dir's
# collapsible nav group opens to that page when clicked.
if p.endswith("/index") or p.endswith("/README"):
bare = p.rsplit("/", 1)[0]
full_id = f"{PREFIX}/{bare}"
parts = bare.split("/")
insert_landing(tree, parts, full_id)
else:
full_id = f"{PREFIX}/{p}"
parts = p.split("/")
insert(tree, parts, full_id)
insert_file(tree, parts, full_id)

def to_mintlify(node, group_name):
pages = []
if "_landing" in node:
pages.append(node["_landing"])
for fname, full_id in sorted(node.get("_files", [])):
pages.append(full_id)
for dname, sub in sorted(node.get("_dirs", {}).items()):
Expand Down
Loading
Loading