diff --git a/docs/hooks.py b/docs/hooks.py new file mode 100644 index 0000000..5ffc76a --- /dev/null +++ b/docs/hooks.py @@ -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 + diff --git a/docs/part/part.md b/docs/part/part.md index 996cdaa..e1f0e80 100644 --- a/docs/part/part.md +++ b/docs/part/part.md @@ -4,6 +4,8 @@ title: Parts ## Part +config.site_url: {{ 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 diff --git a/mkdocs.yml b/mkdocs.yml index 1a9e768..ae1d738 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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 diff --git a/requirements.txt b/requirements.txt index 0fddf8a..6a04e8c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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