Skip to content

Commit c0d1856

Browse files
authored
DOP-5329: Osiris TOC (#646)
* Deserialize toctrees * bughunting * clean * PR feedback, lint, format
1 parent 49c32b6 commit c0d1856

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

snooty/postprocess.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2547,6 +2547,11 @@ def find_toctree_nodes(
25472547
"drawer": slug not in toc_landing_pages
25482548
}
25492549

2550+
# Ensure Osiris-built TOC parent nodes are functional
2551+
if ast.options:
2552+
if ast.options.get("osiris_parent"):
2553+
toctree_node_options = {"drawer": False}
2554+
25502555
# Check if the cleaned slug corresponds to an associated project name, indicating an external node
25512556
if slug in associated_project_names:
25522557
toctree_node_options["project"] = slug
@@ -2709,7 +2714,7 @@ def clean_slug(slug: str) -> str:
27092714
# TODO: remove file extensions in initial parse layer
27102715
# https://jira.mongodb.org/browse/DOCSP-7595
27112716
root, ext = os.path.splitext(slug)
2712-
if ext in SOURCE_FILE_EXTENSIONS:
2717+
if ext in SOURCE_FILE_EXTENSIONS or ext == ".ast":
27132718
return root
27142719

27152720
return slug

snooty/util.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import tomli
5151

5252
from snooty.diagnostics import Diagnostic, NestedProject, UnexpectedNodeType
53-
from snooty.n import FileId
53+
from snooty.n import FileId, TocTreeDirectiveEntry
5454

5555
from . import n, tinydocutils
5656

@@ -525,15 +525,17 @@ def deserialize(
525525
deserialized_children: List[n.Node] = []
526526

527527
for child in node_value:
528+
528529
if not isinstance(child, dict):
529530
continue
530531

531532
child_type: str = child.get("type", "")
532533
child_node_type = cls.node_classes.get(child_type)
534+
533535
if child_node_type:
534536
if (
535537
child_node_type == n.Directive
536-
and node.get("name") == "toctree"
538+
and child.get("name") == "toctree"
537539
):
538540
child_node_type = n.TocTreeDirective
539541

@@ -547,6 +549,24 @@ def deserialize(
547549
filtered_fields[field.name] = deserialized_children
548550
elif field.type == FileId and isinstance(node_value, str):
549551
filtered_fields[field.name] = field.type(node_value)
552+
elif field.name == "entries":
553+
deserialized_entries: List[n.TocTreeDirectiveEntry] = []
554+
555+
if isinstance(node_value, List):
556+
for entry in node_value:
557+
if not isinstance(entry, dict):
558+
continue
559+
560+
title = entry.get("title")
561+
slug = entry.get("slug")
562+
563+
if not title or not slug:
564+
continue
565+
566+
entryNode = TocTreeDirectiveEntry(title, None, slug, None)
567+
deserialized_entries.append(entryNode)
568+
569+
filtered_fields[field.name] = deserialized_entries
550570
else:
551571
# Ideally, we validate that the data types of the fields match the data types of the JSON node,
552572
# but that requires a more verbose and time-consuming process. For now, we assume data types are correct.

0 commit comments

Comments
 (0)