Sphinx extension to add a warning banner
Project description
Sphinx Version Warning is a Sphinx extension that allows you to show a Warning banner at the top of your documentation. The banner is shown based on the version that is displayed compared (using SemVer) with the latest version on the server.
This extension was originally created to be compatible with Read the Docs API and currently it’s the only backend that supports (inspired by https://github.com/rtfd/readthedocs.org/issues/3481#issuecomment-378000845)
How it works?
When visiting a page in Read the Docs that was built with this extension enabled, an AJAX request is done to the Read the Docs servers to retrieve all the versions of the project. These versions are compared against the one that we are reading and if it’s an old version, a red Warning banner appears at the top of the page.
Examples
There is a live example living at Read the Docs:
latest version doesn’t show any kind of warning banner
0.0.1 version shows a custom and fixed message added at build time
0.0.2 version shows a warning banner saying that 0.0.3 is available (at the time of writing this docs)
0.0.3 version doesn’t show any banner since it’s the latest version (at the time of writing this docs)
Installation
Just run this pip command insider your virtualenv:
pip install sphinx-version-warning
Then in your conf.py you have to add versionwarning in the extensions list. Should be similar to:
extensions = [ 'versionwarning', ]
Enable it and setup the Read the Docs project’s slug:
versionwarning_enabled = True versionwarning_project_slug = 'sphinx-version-warning'
Remember to configure the version of your Sphinx project since it’s the key for this to work properly:
version = '0.0.1'
Customization
Some customization can be done using the conf.py file of your Sphinx project:
- versionwarning_enabled (bool)
enable/disable version warning extension
- versionwarning_default_admonition_type (string)
type of admonition for the banner (warning, admonition or note)
- versionwarning_default_message (string)
default message for the warning banner
- versionwarning_messages (dict)
mapping between versions and messages for its banners
- versionwarning_message_placeholder (string)
text to be replaced by the version number link from the message
- versionwarning_project_slug (string)
slug of the project under Read the Docs
- versionwarning_api_url (string)
API URL to retrieve all versions for this project
- versionwarning_banner_html (string)
HTML code used for the banner shown
- versionwarning_banner_id_div (string)
HTML element ID used for the <div> inject as banner
- versionwarning_body_default_selector (string)
jQuery selector to find the body element in the page
- versionwarning_body_extra_selector (string)
jQuery selector to find the body element in the page if versionwarning_body_default_selector wasn’t found
How to contribute?
Pull Requests are always welcome!
Generate assets
npm install ./node_modules/.bin/webpack
Releasing
1. Increment the version in __init__.py 1. Increment the version in package.json 1. Update the CHANGELOG.rst 1. Tag the release in git: git tag $NEW_VERSION. 1. Push the tag to GitHub: git push –tags origin 1. Upload the package to PyPI:
$ rm -rf dist/ $ python setup.py sdist bdist_wheel $ twine upload dist/*
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sphinx-version-warning-0.1.0.tar.gz
.
File metadata
- Download URL: sphinx-version-warning-0.1.0.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a889936a404a20069c1c88182c961ebf9779c6eeacd2b9f26d5dbd7203b483b |
|
MD5 | ff7d83a40ef659eae7387aa349d9f400 |
|
BLAKE2b-256 | 3d602a702a1ca022dea8a8a0e00b6564a44787b059c45b5169b8e6a621ed1ac9 |
File details
Details for the file sphinx_version_warning-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: sphinx_version_warning-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d2e540fc533dbb21fdf6fd634e2b92b9e026366fb9d65d3c0a0c7369c455a25 |
|
MD5 | eb9dc8f2360c81ba01316bac133dff0d |
|
BLAKE2b-256 | 5bc69af5ea063a32b641c31d0ef06b73f209be27e46083eed3bde4782957fe4c |