From 01c6b15b620b36a02cd6ab9bfa1493ac1918050c Mon Sep 17 00:00:00 2001 From: Matt McKay Date: Mon, 15 Jun 2020 15:57:27 +1000 Subject: [PATCH] add support for next and prev metadata to exclude items (e.g. hidden tocs) --- sphinxcontrib/jupyter/__init__.py | 1 + sphinxcontrib/jupyter/builders/jupyter.py | 32 ++++++++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/sphinxcontrib/jupyter/__init__.py b/sphinxcontrib/jupyter/__init__.py index eb1fdb65..a8b26634 100644 --- a/sphinxcontrib/jupyter/__init__.py +++ b/sphinxcontrib/jupyter/__init__.py @@ -71,6 +71,7 @@ def setup(app): app.add_config_value("jupyter_template_path", "templates", "jupyter") app.add_config_value("jupyter_dependencies", None, "jupyter") app.add_config_value("jupyter_download_nb_execute", None, "jupyter") + app.add_config_value("jupyter_nextprev_ignore", [], "jupyter") # Jupyter pdf options app.add_config_value("jupyter_latex_template", None, "jupyter") diff --git a/sphinxcontrib/jupyter/builders/jupyter.py b/sphinxcontrib/jupyter/builders/jupyter.py index c03151ed..b7801b74 100644 --- a/sphinxcontrib/jupyter/builders/jupyter.py +++ b/sphinxcontrib/jupyter/builders/jupyter.py @@ -215,20 +215,32 @@ def update_Metadata(self, docname, nb): titles = self.env.titles if related and related[2]: try: - next_doc = { - 'link': self.get_relative_uri(docname, related[2]), - 'title': titles[related[2]].children[0].astext() - } - nb.metadata.next_doc = next_doc + link = self.get_relative_uri(docname, related[2]) + title = titles[related[2]].children[0].astext() + # link is document uri (i.e. docname) as specified in index + if link in self.config.jupyter_nextprev_ignore: + pass + else: + next_doc = { + 'link': link, + 'title': title + } + nb.metadata.next_doc = next_doc except KeyError: nb.metadata.next_doc = False if related and related[1]: try: - prev_doc = { - 'link': self.get_relative_uri(docname, related[1]), - 'title': titles[related[1]].children[0].astext() - } - nb.metadata.prev_doc = prev_doc + link = self.get_relative_uri(docname, related[1]) + title = titles[related[1]].children[0].astext() + # link is document uri (i.e. docname) as specified in index + if link in self.config.jupyter_nextprev_ignore: + pass + else: + prev_doc = { + 'link': link, + 'title': title + } + nb.metadata.prev_doc = prev_doc except KeyError: nb.metadata.prev_doc = False # Set Compile Datetime