Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configure nbsphinx to generate html tags from notebook metadata? #722

Open
tylerflex opened this issue Mar 14, 2023 · 1 comment
Open

configure nbsphinx to generate html tags from notebook metadata? #722

tylerflex opened this issue Mar 14, 2023 · 1 comment

Comments

@tylerflex
Copy link

Our .ipynb files contain basic metadata that we want to embed in the eventual html in our sphinx-generated docs.

As an example:

# Example.ipynb
{
    "metadata": {
        "title": "A Well Written Title.",
        "description": "A meta tag description.",
        ...
    },
    "cells" : [...]
}
# Example.html
<title>A Well Written Title.</title>
<meta name="description"  content=A meta tag description. />

How can I accomplish this with nbsphinx?

With nbconvert, I am able to use a custom template with the following lines in it

{% set nb_title = nb.metadata.get('title', '') or resources['metadata']['name'] %}
<title>{{nb_title}}</title>

{% set nb_descr = nb.metadata.get('description', '') %}
<meta name="description"  content={{nb_descr}} />

Is it possible to specify nbsphinx to use this template in my conf.py? Or is there a way to replicate this behavior in nbsphinx configuration?

Any other approaches you can recommend?
Thanks!

@mgeier
Copy link
Member

mgeier commented Mar 19, 2023

Is is not possible to use nbconvert templates with nbsphinx, because it doesn't use nbconvert to create the HTML output. Instead, Sphinx is using its own templates, see e.g. https://github.com/sphinx-doc/sphinx/blob/master/sphinx/themes/basic/layout.html

I'm sure this can be implemented rather easily. The template uses the title and titlesuffix Jinja variables, which I guess can be somehow set during the build process.
And there is a metatags variable which can probably be used for the description thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants