Repository: executablebooks/jupyter-book
File: jupyter_book/directive/toc.py (Python)

Code before:
        """ Filters globaltoc to take children of the current page only
        """
        for key, val in globaltoc.items():
            if key == "file":
                if val == self.env.docname:
                    del globaltoc[key]
                    return globaltoc
            if key == "sections":
                for item in val:
                    if "file" in item and item["file"] == self.env.docname:
                        del item["file"]
                        return item
                    elif "sections" in item:
                        globaltoc = self._process_toc_dict(item)
        return globaltoc

    def _has_toc_yaml(self, subnode, tocdict, depth):
        """ constructs toc nodes from globaltoc dict
        """
        depth += 1
        for key, val in tocdict.items():
            if key == "header":
                header = self._handle_toc_header(subnode, val, depth)
                subnode["classes"].append("ls-none")
                subnode.append(header)
            if key == "file" or key == "url":
                if "title" in tocdict:
                    title = tocdict["title"]
                else:
                    if val not in self.env.titles:
                        continue
                    title = clean_astext(self.env.titles[val])
                if key == "url":
                    val = val
                    internal = False
                else:
                    val = "/" + val + self.env.app.builder.out_suffix
                    internal = True
                reference = nodes.reference(
                    "",
                    "",
                    internal=internal,
                    refuri=val,
                    anchorname="",
                    *[nodes.Text(title)]
                )
                para = addnodes.compact_paragraph("", "", reference)
                item = nodes.list_item("", para)
                item["classes"].append("toctree-l%d" % (depth))
                subnode.append(item)
            if key == "sections":

Review comment (suggestion):
```suggestion
            if key in ["file", "url"]:
```

Code after:
        """ Filters globaltoc to take children of the current page only
        """
        for key, val in globaltoc.items():
            if key == "file":
                if val == self.env.docname:
                    del globaltoc[key]
                    return globaltoc
            if key == "sections":
                for item in val:
                    if "file" in item and item["file"] == self.env.docname:
                        del item["file"]
                        return item
                    elif "sections" in item:
                        globaltoc = self._process_toc_dict(item)
        return globaltoc

    def _has_toc_yaml(self, subnode, tocdict, depth):
        """ constructs toc nodes from globaltoc dict
        """
        depth += 1
        for key, val in tocdict.items():
            if key == "header":
                header = self._handle_toc_header(subnode, val, depth)
                subnode["classes"].append("ls-none")
                subnode.append(header)
            if key in ["file", "url"]:
                if "title" in tocdict:
                    title = tocdict["title"]
                else:
                    if val not in self.env.titles:
                        continue
                    title = clean_astext(self.env.titles[val])
                if key == "url":
                    if "http" in val:
                        val = val
                        internal = False
                    else:
                        # since "file" key will be anyways for each "url" key
                        continue
                else:
                    val = "/" + val + self.env.app.builder.out_suffix
                    internal = True
                reference = nodes.reference(
                    "",
                    "",
                    internal=internal,
                    refuri=val,
                    anchorname="",
                    *[nodes.Text(title)]
                )
                para = addnodes.compact_paragraph("", "", reference)