code: def generate_page_toc(soup):
    
    # Maybe we don't want to show all the headings. E.g., it's common for a page
    # to have just one H1, a title at the top. Our heuristic: if a page has just
    # one heading of some outline level, don't show it.
    found_depth_counts = collections.defaultdict(int)
    for tag in soup.find_all(_heading_re):
      if (tag.get('id') or tag.get('name')):
        found_depth_counts[hdepth(tag)] += 1
  
    depth_list = [i for i in range(100) if 1 < found_depth_counts[i]]
    depth_list = depth_list[:4]
    toc = []
    for tag in soup.find_all(_heading_re):
      depth = hdepth(tag)
      if depth in depth_list:
        toc.append(dict(depth=depth_list.index(depth) + 1,
                        link=tag.get('id') or tag.get('name'),
                        text=tag.text))
    return toc
docs: Return page-level (~list of headings) TOC template data for soup