Skip to content

Commit 73a486b

Browse files
authored
Merge pull request #15 from ewellinger/homepage_detection_14
Fix non-standard homepage location
2 parents 7029609 + 7a814e4 commit 73a486b

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

mkdocs_charts_plugin/plugin.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import os
22

3-
from mkdocs.plugins import BasePlugin
43
from mkdocs.config import config_options
54
from mkdocs.exceptions import PluginError
5+
from mkdocs.plugins import BasePlugin
66
from mkdocs.utils import copy_file
77

88
from mkdocs_charts_plugin.fences import fence_vegalite
@@ -23,7 +23,6 @@ def check_library(libnames, dependency):
2323

2424

2525
class 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

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="mkdocs-charts-plugin",
8-
version="0.0.8",
8+
version="0.0.9",
99
description="MkDocs plugin to add charts from data",
1010
long_description=long_description,
1111
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)