Skip to content

Commit

Permalink
add support for next and prev metadata to exclude items (e.g. hidden …
Browse files Browse the repository at this point in the history
…tocs) (#330)
  • Loading branch information
mmcky authored Jun 15, 2020
1 parent 1e162ad commit 496ede8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions sphinxcontrib/jupyter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
32 changes: 22 additions & 10 deletions sphinxcontrib/jupyter/builders/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 496ede8

Please sign in to comment.