11import os
22
3- from mkdocs .plugins import BasePlugin
43from mkdocs .config import config_options
54from mkdocs .exceptions import PluginError
5+ from mkdocs .plugins import BasePlugin
66from mkdocs .utils import copy_file
77
88from mkdocs_charts_plugin .fences import fence_vegalite
@@ -23,7 +23,6 @@ def check_library(libnames, dependency):
2323
2424
2525class ChartsPlugin (BasePlugin ):
26-
2726 config_scheme = (
2827 ("data_path" , config_options .Type (str , default = "" )),
2928 ("use_data_path" , config_options .Type (bool , default = True )),
@@ -41,16 +40,10 @@ def on_config(self, config, **kwargs):
4140 """
4241 # Add pointer to mkdocs-charts-plugin.js
4342 # which is added to the output directory during on_post_build() event
44- config ["extra_javascript" ] = ["js/mkdocs-charts-plugin.js" ] + config [
45- "extra_javascript"
46- ]
43+ config ["extra_javascript" ] = ["js/mkdocs-charts-plugin.js" ] + config ["extra_javascript" ]
4744
4845 # Make sure custom fences are configured.
49- custom_fences = (
50- config .get ("mdx_configs" , {})
51- .get ("pymdownx.superfences" , {})
52- .get ("custom_fences" , {})
53- )
46+ custom_fences = config .get ("mdx_configs" , {}).get ("pymdownx.superfences" , {}).get ("custom_fences" , {})
5447 if not custom_fences :
5548 raise PluginError (
5649 "[mkdocs_charts_plugin]: You have not configured any custom fences, please see the setup instructions."
@@ -62,13 +55,6 @@ def on_config(self, config, **kwargs):
6255 check_library (libnames , "vega-lite" )
6356 check_library (libnames , "vega-embed" )
6457
65- def on_page_content (self , html , page , config , files , ** kwargs ):
66- """
67- Store reference to homepage
68- """
69- if page .is_homepage :
70- self .homepage = page .file
71-
7258 def on_post_page (self , output , page , config , ** kwargs ):
7359 """
7460 Insert plugin config as javascript variables into the page.
@@ -101,9 +87,11 @@ def add_javascript_variables(self, html, page, config):
10187 """
10288 plugin_config = self .config .copy ()
10389
104- # Find path to homepage
105- path_to_homepage = self .homepage .url_relative_to (page .file )
106- path_to_homepage = os .path .dirname (path_to_homepage )
90+ # Find the path to the homepage
91+ docs_directory = config ["docs_dir" ]
92+ page_path = os .path .join (docs_directory , page .file .src_uri )
93+ path_to_homepage = os .path .relpath (docs_directory , os .path .dirname (page_path ))
94+
10795 if config .get ("use_directory_urls" ):
10896 path_to_homepage = os .path .join (".." , path_to_homepage )
10997 plugin_config ["path_to_homepage" ] = path_to_homepage
0 commit comments