def filter_toc()

in update-toc.py [0:0]


def filter_toc(toc_dict, namespaces, path_resolver):
    if toc_dict is None:
        return None
    # internal node
    if "items" in toc_dict:
        # recurse as mant times as necessary
        item_list = []
        for item in toc_dict['items']:
            result_n = filter_toc(item, namespaces, path_resolver)
            # only append the result if we know it exists
            if result_n:
                item_list.append(result_n)
        if item_list:
            toc_dict["items"] = item_list
        else:
            return None

    # handle href
    if "href" in toc_dict:
        toc_dict = path_resolver.amend_href(toc_dict)

    # leaf node
    if "children" in toc_dict:
        filtered_children = filter_children(toc_dict["children"], namespaces)
        # if we filter out all the children, this node should simply cease to exist
        if not filtered_children:
            return None
    elif "href" not in toc_dict and "items" not in toc_dict:
        return None

    return toc_dict