Sphinx extension to generateOpen Graph metadata for your documentation.
python-mpipinstallsphinxext-opengraph
Thematplotlib package is required to generate social cards:
python-mpipinstallsphinxext-opengraph[social_cards]
Addsphinxext.opengraph to the extensions list inconf.py:
extensions=['sphinxext.opengraph',]
Then set theogp_site_url configuration valueto the public URL for your documentation, e.g.:
ogp_site_url='https://docs.example.org/'
Tip
Documentation hosted on Read The Docs automatically detects the site URLthrough theREADTHEDOCS_CANONICAL_URL environment variable,so no configuration is needed.
These values are placed in theconf.py of your Sphinx project.
str''This config option is important, set it to the URL the site is being hosted on.
int200Configure the number of characters taken from a page.
str|Literal[False]projectName of the site.This is displayed above the title.Defaults to theproject config value.Set toFalse to unset and use no default.
dict[str,bool|str]{}Configuration for automatically creating social media card PNGs for each page.Seethe social media cards page for more information.
str|NoneNoneLink to image to show.Note that all relative paths are converted to be relative tothe root of the HTML output as defined byogp_site_url.
str|Literal[False]NoneAlt text for image.Defaults to usingogp_site_name or the document’s title as alt text,if available.Set toFalse to disable alt text.
boolFalseSet toTrue to use each page’s first image, if available.If set toTrue but no image is found, Sphinx will useogp_image instead.
str'website'This sets the ogp type attribute.For more information on the types available, see athttps://ogp.me/#types.By default, it is set towebsite, which should be fine for most use cases.
Sequence[str]()List of custom HTML snippets to insert.
boolTrueWhenTrue, generates<metaname="description"content="..."> from the page.
strogp_site_urlThis option can be used to override the “canonical” URL for the page,and is used forog:url and the URL text in generated social media preview cards.It is most useful with versioned documentation, where you intendto set the “stable” or “latest” version as the canonical location of each page,similarly torel="canonical".If not set, the option defaults to the value ofogp_site_url.
ogp_site_url="http://example.org/"ogp_image="http://example.org/image.png"
ogp_site_url="http://example.org/"ogp_image="http://example.org/image.png"ogp_description_length=300ogp_type="article"ogp_custom_meta_tags=['<meta property="og:ignore_canonical" content="true" />',]ogp_enable_meta_description=True
Field lists can be used to override certain settings on each pageand set unsupported arbitrary Open Graph tags.
Make sure you place the fields at the very start of the documentsuch that Sphinx will pick them up and also won’t build them into the HTML.
These are some overrides that can be used on individual pages,you can actually override any tag and field lists will always take priority.
:ogp_description_length:Configure the amount of characters to grab for the description of the page.If the value isn’t a number it will fall back toogp_description_length.
:ogp_disable:Disables generation of Open Graph tags on the page.
:og:description:Lets you override the description of the page.
:description: or..meta:::description:Sets the<metaname="description"content="..."> description.
:og:title:Lets you override the title of the page.
:og:type:Override the type of the page.For the list of available types, see athttps://ogp.me/#types.
:og:image:Set the image for the page.
Note: Relative file paths for images, videos and audioare currently not supported when using field lists.Please use an absolute path instead.
:og:image:alt:Sets the alt text. Will be ignored if there is no image set.
Remember that the fieldsmust be placed at the very start of the file.You can verify Sphinx has picked up the fields if they aren’t shownin the final HTML file.
:og:description: New description:og:image: http://example.org/image.png:og:image:alt: Example ImagePage contents=============
Additionally, you can use field lists to add any arbitrary Open Graph tagnot supported by the extension.The syntax for arbitrary tags is the same with:og:tag:content.
For example:
:og:video: http://example.org/video.mp4Page contents=============
Note: Relative file paths for images, videos and audioare currently not supported when using field lists.Please use an absolute path instead.