spatialaudio / nbsphinx

:ledger: Sphinx source parser for Jupyter notebooks
https://nbsphinx.readthedocs.io/
MIT License
450 stars 130 forks source link

Build gallery with Jupyter-Book #668

Closed mdtanker closed 2 years ago

mdtanker commented 2 years ago

Hi, I'm using jupyter-books to create the docs for my python package Antarctic-Plots and I'm trying to set up a gallery of examples from a series of jupyter notebooks, following this guide.

I've managed to create a .html of the gallery, but instead of thumbnails, it's just a bullet point list of the .ipynb's, as in the following screenshot.

image

To do this, I've added the following to the _config.yml:

  config:
    sphinx_gallery_conf : {
      'examples_dirs': "examples",
      'gallery_dirs': "auto_examples",
      'image_scrapers': pygmt.sphinx_gallery.PyGMTScraper(),
                          }

and I've added this to my _toc.yml:

  - title: 👀 Gallery
    file: gallery/gallery

which points to the file gallery.ipynb, which has a metadata cell tag nbsphinx-gallery:

# Gallery

* [Basic Plot](basic_plot.ipynb)
* [Extend PyGMT](extend_pygmt.ipynb)

Any advice for how to fix this and have the thumbnails display properly? This issue persists whether or not the ipynb's have the metadata cell tag: nbsphinx-thumbnail.

Possibly unrelated, but I've had to add source_suffix: ['.rst', '.ipynb'] to my _config.yml, or else I got the following error:

sphinx.errors.ExtensionError: source_suffix '.ipynb' is already registered
mgeier commented 2 years ago

jupyter-book and nbsphinx are two separate projects. The former doesn't seem to support galleries yet (see https://github.com/executablebooks/jupyter-book/issues/1785).

Your setting sphinx_gallery_conf is from yet another project: sphinx-gallery. You might be able to use that, but the usage is different than in nbsphinx. Have a look at their docs for how to set it up. You won't need nbsphinx for that.

If you want to use the gallery feature from nbsphinx, you'll also have to use nbsphinx to parse your notebooks (instead of jupyter-book), otherwise the thumbnails will not be generated. Note that when you use nbsphinx, you'll have to remove .ipynb from source_suffix again.

mdtanker commented 2 years ago

Thanks for the response. I couldn't manage to get nbsphinx to work with my jupyter-book setup, but have resorted to a simple mardown file with the gallery examples for now.