mirror of
				https://github.com/inventree/inventree-docs.git
				synced 2025-10-31 04:45:38 +00:00 
			
		
		
		
	Add custom hooks
This commit is contained in:
		
							
								
								
									
										55
									
								
								docs/hooks.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								docs/hooks.py
									
									
									
									
									
										Normal 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 | ||||||
|  |  | ||||||
| @@ -4,6 +4,8 @@ title: Parts | |||||||
|  |  | ||||||
| ## Part | ## 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. | 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  | ## Part Category  | ||||||
|   | |||||||
| @@ -128,6 +128,9 @@ nav: | |||||||
| plugins: | plugins: | ||||||
|   - search |   - search | ||||||
|   - git-revision-date-localized |   - git-revision-date-localized | ||||||
|  |   - mkdocs-simple-hooks: | ||||||
|  |       hooks: | ||||||
|  |         on_config: "docs.hooks:on_config" | ||||||
|   - macros: |   - macros: | ||||||
|       include_dir: _includes |       include_dir: _includes | ||||||
|  |  | ||||||
|   | |||||||
| @@ -11,6 +11,7 @@ mkdocs-macros-plugin>=0.4.9,<1.0 | |||||||
| mkdocs-material>=7.1,<8.0 | mkdocs-material>=7.1,<8.0 | ||||||
| mkdocs-material-extensions>=1.0,<2.0 | mkdocs-material-extensions>=1.0,<2.0 | ||||||
| mkdocs-git-revision-date-localized-plugin==0.9.2 | mkdocs-git-revision-date-localized-plugin==0.9.2 | ||||||
|  | mkdocs-simple-hools==0.1.3 | ||||||
| nltk>=3.5,<4.0 | nltk>=3.5,<4.0 | ||||||
| Pygments>=2.7.1,<3.0 | Pygments>=2.7.1,<3.0 | ||||||
| pymdown-extensions>=8.0,<9.0 | pymdown-extensions>=8.0,<9.0 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user