-
-
Notifications
You must be signed in to change notification settings - Fork 64
Description
Question
Is it possible to get the version from the docs URL (e.g. /3/
, /3.12/
or /3.10.7/
) in conf.py
?
Why?
I'm looking at adding OpenGraph metadata to the docs to help with SEO (see python/pythondotorg#1691).
And there's a handy Sphinx extension that can help: https://pypi.org/project/sphinxext-opengraph/
We need to add config like ogp_site_url = "http://example.org/"
For example:
ogp_site_url = "https://docs.python.org/3/"
Produces something like:
<meta property="og:url" content="https://docs.python.org/3/library/csv.html" />
However, the version in the URL isn't necessarily /3/
, it could include minor version (https://docs.python.org/3.12/) or even patch version (https://docs.python.org/release/3.10.7/), so we can't hardcode it.
Is this path version available in conf.py
?
conf.py
already has:
# We look for the Include/patchlevel.h file in the current Python source tree
# and replace the values accordingly.
import patchlevel
version, release = patchlevel.get_version_info()
But these are like 3.12, 3.12.0a0
, and don't necessarily match the URL version (which could be any of major[.minor[.patch]]
.
Thanks!