2
0
mirror of https://github.com/inventree/inventree-docs.git synced 2025-04-27 21:26:43 +00:00

Merge pull request #189 from inventree/fix-site-urls

Add  custom hooks

(cherry picked from commit 9dfc67df4494960143e959ac7df495f7c9253f79)
This commit is contained in:
Oliver 2021-10-11 18:04:59 +11:00
parent 9694e08278
commit 1a35e2caf0
4 changed files with 61 additions and 0 deletions

55
docs/hooks.py Normal file
View File

@ -0,0 +1,55 @@
"""
Custom mkdocs hooks, using the mkdocs-simple-hooks plugin
"""
import os
def on_config(config, *args, **kwargs):
"""
Hosting multiple versions of the documenation on readthedocs.io is complex,
as the required interactions between rtd and mkdocs do not exist.
We want to be able to provide a *dynamic* config.site_url parameter to mkdocs,
which tells it the base url, e.g.
- https://readthedocs.io/en/latest
- https://readthedocs.io/de/0.5.1
Further, we need to know if we are building on readthedocs at all!
readthedocs provides some environment variables:
- https://docs.readthedocs.io/en/stable/builds.html#build-environment
We can use these to determine (at run time) where we are hosting
"""
rtd = os.environ.get('READTHEDOCS', False)
if not rtd:
print("'READTHEDOCS' environment variable not found")
print("Building for localhost configuration!")
else:
rtd_version = os.environ['READTHEDOCS_VERSION']
rtd_language = os.environ['READTHEDOCS_LANGUAGE']
url = f"https://inventree.readthedocs.io/{rtd_language}/{rtd_version}"
config['site_url'] = url
return config
def my_cfg(config, *args, **kwargs):
# print(config.keys())
for k in config.keys():
print(f"- {k}")
print(config['site_url'])
return config

View File

@ -4,6 +4,8 @@ title: Parts
## Part
<b>config.site_url:</b> {{ config.site_url }}
The *Part* is the core element of the InvenTree ecosystem. A Part object is the archetype of any stock item in your inventory. Parts are arranged in heirarchical categories which are used to organise and filter parts by function.
## Part Category

View File

@ -125,6 +125,9 @@ nav:
plugins:
- search
- git-revision-date-localized
- mkdocs-simple-hooks:
hooks:
on_config: "docs.hooks:on_config"
- macros:
include_dir: _includes

View File

@ -11,6 +11,7 @@ mkdocs-macros-plugin>=0.4.9,<1.0
mkdocs-material>=7.1,<8.0
mkdocs-material-extensions>=1.0,<2.0
mkdocs-git-revision-date-localized-plugin==0.9.2
mkdocs-simple-hooks==0.1.3
nltk>=3.5,<4.0
Pygments>=2.7.1,<3.0
pymdown-extensions>=8.0,<9.0