wpilibsuite / sphinxext-opengraph

Sphinx extension to generate unique OpenGraph metadata
https://sphinxext-opengraph.readthedocs.io
Other
74 stars 27 forks source link
hacktoberfest sphinx-extension

sphinxext-opengraph

Build Code style: Black

Sphinx extension to generate Open Graph metadata for each page of your documentation.

Installation

python -m pip install sphinxext-opengraph

Usage

Just add sphinxext.opengraph to your extensions list in your conf.py

extensions = [
   "sphinxext.opengraph",
]

Options

These values are placed in the conf.py of your Sphinx project.

Users hosting documentation on Read The Docs do not need to set any of the following unless custom configuration is wanted. The extension will automatically retrieve your site URL.

Example Config

Simple Config

ogp_site_url = "http://example.org/"
ogp_image = "http://example.org/image.png"

Advanced Config

ogp_site_url = "http://example.org/"
ogp_image = "http://example.org/image.png"
ogp_description_length = 300
ogp_type = "article"

ogp_custom_meta_tags = [
    '<meta property="og:ignore_canonical" content="true" />',
]

ogp_enable_meta_description = True

Per Page Overrides

Field lists are used to allow you to override certain settings on each page and set unsupported arbitrary Open Graph tags.

Make sure you place the fields at the very start of the document such that Sphinx will pick them up and also won't build them into the html.

Overrides

These are some overrides that can be used on individual pages, you can actually override any tag and field lists will always take priority.

Example

Remember that the fields must be placed at the very start of the file. You can verify Sphinx has picked up the fields if they aren't shown in the final html file.

:og:description: New description
:og:image: http://example.org/image.png
:og:image:alt: Example Image

Page contents
=============

Arbitrary Tags[^2]

Additionally, you can use field lists to add any arbitrary Open Graph tag not supported by the extension. The syntax for arbitrary tags is the same with :og:tag: content. For example:

:og:video: http://example.org/video.mp4

Page contents
=============

[^1]: Note the slightly different syntax because this isn't directly an Open Graph tag. [^2]: Note: Relative file paths for images, videos and audio are currently not supported when using field lists. Please use an absolute path instead.