Search code examples
python-sphinxrestructuredtext

How to set opengraph metadata tags for a sphinx document?


I'm looking to add meta tags to my sphinx document for the opengraph properties.

I see that sphinx has this meta directive

.. meta::
   :description: The Sphinx documentation builder
   :keywords: Sphinx, documentation, builder

But how do I use it to tags with the property attribute like <meta property="og:title" content="<title>" /> -- I only see examples with the name attribute?

I see that there's also the sphinxext-opengraph extension, but it looks like that uses conf.py to specify the tags, and I want to manually set the tags for each RST document.


Solution

  • The aforementioned sphinxext-opengraph extension currently has a PR for setting the values per page. The PR is effectivley done so a new version should be released very soon.

    Edit: The PR has been merged. You can now set any tag by adding field lists to the top of the page like so:

    :og:description: New description
    
    Page Title
    ==========
    

    For more info refer to the docs or the readme in the repo.

    Edit 2: Currently relative image/video/audio file paths are broken on purpose, this will be fixed with #53