nbsphinx icon indicating copy to clipboard operation
nbsphinx copied to clipboard

How can I set a HTML meta description tag in the HTML page generated from my notebook ?

Open fabiencelier opened this issue 4 years ago • 3 comments

I use nbsphinx to generate a few HTML pages from notebooks. Can I set the meta description tag of these pages somewhere in my notebooks ?

fabiencelier avatar Sep 01 '20 09:09 fabiencelier

Currently, there is no special feature in nbsphinx for this.

However, you should be able to do this in a raw reST cell using the meta directive: https://docutils.sourceforge.io/docs/ref/rst/directives.html#meta

I think it would be possible to implement this in nbsphinx using notebook metadata (probably using sphinx.addnodes.meta).

Would you like to make a PR for this?

mgeier avatar Sep 04 '20 09:09 mgeier

I guess I could add the reST meta directive cell but I also share my notebook as examples and I don't want to trouble my users with a weird first cell.

The notebook metadata would be a much cleaner solution :smiley: I'll try to have a look at it but I'm not sure when I'll have the time.

Is there any other code that uses the notebook metadata at the moment that can use as a starting point ?

fabiencelier avatar Sep 04 '20 10:09 fabiencelier

I don't want to trouble my users with a weird first cell.

It doesn't have to be the first cell. But I agree, it's weird.

Is there any other code that uses the notebook metadata at the moment that can use as a starting point ?

The currently supported notebook metadata is handled there (and in the following lines):

https://github.com/spatialaudio/nbsphinx/blob/82859f01872fbafc78b2b28b2a192a86fc23e51b/src/nbsphinx.py#L794

You should be able to simply add the meta directive at the beginning (or the end?) of the variable rststr (which is created a few lines further down).

mgeier avatar Sep 04 '20 14:09 mgeier