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 active versions of the project. These versions are compared against the one that we are reading and if it’s an old version, a Warning banner appears at the top of the page.
Examples
There is a live example living at Read the 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', ]
Remember to configure the versionwarning_project_version and versionwarning_project_slug of your Sphinx project since it’s the key for this to work properly:
versionwarning_project_version = '0.0.1' versionwarning_project_slug = 'sphinx-version-warning'
Customization
Some customization can be done using the conf.py file of your Sphinx project:
- versionwarning_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 (default to READTHEDOCS_PROJECT environment variable)
- versionwarning_project_version (string)
slug of the version for the current documentation (default to READTHEDOCS_VERSION environment variable)
- 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_selector (string)
jQuery selector to find the body element in the page and prepend the banner
How to contribute?
Pull Requests are always welcome!
Generate assets
npm install ./node_modules/.bin/webpack
Releasing
Increment the version in versionwarning/__init__.py
Increment the version in package.json
Update the CHANGELOG.rst
Compile assets:
$ npm install $ ./node_modules/.bin/webpack
Tag the release in git: git tag $NEW_VERSION
Push the tag to GitHub: git push --tags origin
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
Hashes for sphinx-version-warning-1.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e85c2b09b5d1ffb1c05baac256c9fb93e915e12d825a80546a47c27efbb03644 |
|
MD5 | bcfb5c5f599ea612a1516d997d50798e |
|
BLAKE2b-256 | 6e38b42a1bb7c993f510feebf65911e75fbb1b3be90e4d8bfbe98318a9f0fc29 |
Hashes for sphinx_version_warning-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50f0b3bd298d5ae9b28e06392f49f7a3b689549e145e241feef81b2418d694ee |
|
MD5 | c0a9bcc462ac76df43ff87c32deca428 |
|
BLAKE2b-256 | 7387913f70a0f6bf195e14dfa96b45a5afa1a3a6f06343f41c1fdf4c376a6fc0 |