Repository: carbon-language/carbon-lang
File: website/prebuild.py (Python)

Code before:
    subdir_str: str,
    top_nav_order: int,
    parent_title: Optional[str] = None,
    grandchild_dirs: bool = False,
) -> None:
    """Automatically adds child information to a subdirectory's markdown files.

    This is in support of navigation.
    """
    assert not (parent_title and grandchild_dirs)

    subdir = Path(subdir_str)
    readme = subdir / "README.md"
    readme_content = readme.read_text()

    readme_title = get_title(readme, readme_content)
    readme_titles = [readme_title]
    if parent_title:
        readme_titles.insert(0, parent_title)
    children = [
        x
        for x in subdir.glob("**/*.md")
        if x != readme
        and "/node_modules/" not in str(x)
        and "/dist/" not in str(x)
    ]
    add_frontmatter(
        readme, readme_content, readme_titles, top_nav_order, bool(children)
    )

    if grandchild_dirs:
        # When adding grandchildren, we cluster files by child directory.
        child_dirs = {}
        for child in children:
            if child.name == "README.md":
                title = get_title(child, child.read_text())
                child_dirs[child.parent] = ChildDir(title)
        for child in children:
            if child.name != "README.md" and child.parent in child_dirs:
                child_dirs[child.parent].has_grandchildren = True

    for child in children:
        child_content = child.read_text()
        child_title = get_title(child, child_content)
        child_nav_order = None

        if subdir_str == "proposals":
            # Use proposal numbers as part of the title and ordering.
            m = re.match(r"p(\d+).md", child.name)
            # Skip files that aren't proposals.
            if not m:

Review comment (suggestion):
```suggestion
    children = []
    for x in subdir.glob("**/*.md"):
      if x != readme and not ("/node_modules/" in str(x) or "/dist/" in str(x)):
        children.append(x)
```

This just because of the difficulty of reading multi-line comprehension conditions

Code after:
    subdir_str: str,
    top_nav_order: int,
    parent_title: Optional[str] = None,
    grandchild_dirs: bool = False,
) -> None:
    """Automatically adds child information to a subdirectory's markdown files.

    This is in support of navigation.
    """
    assert not (parent_title and grandchild_dirs)

    subdir = Path(subdir_str)
    readme = subdir / "README.md"
    readme_content = readme.read_text()

    def include_child(md_file: Path) -> bool:
        """Returns whether md_file is a child of this label."""
        # The top-level README.md isn't a child.
        if md_file == readme:
            return False
        # Skip directories that aren't part of the repository.
        if "/node_modules/" in str(md_file):
            return False
        if "/dist/" in str(md_file):
            return False
        return True

    readme_title = get_title(readme, readme_content)
    readme_titles = [readme_title]
    if parent_title:
        readme_titles.insert(0, parent_title)
    children = [x for x in subdir.glob("**/*.md") if include_child(x)]
    add_frontmatter(
        readme, readme_content, readme_titles, top_nav_order, bool(children)
    )

    if grandchild_dirs:
        # When adding grandchildren, we cluster files by child directory.
        child_dirs = {}
        for child in children:
            if child.name == "README.md":
                title = get_title(child, child.read_text())
                child_dirs[child.parent] = ChildDir(title)
        for child in children:
            if child.name != "README.md" and child.parent in child_dirs:
                child_dirs[child.parent].has_grandchildren = True

    for child in children:
        child_content = child.read_text()
        child_title = get_title(child, child_content)
        child_nav_order = None