Skip to content

Commit c00d85d

Browse files
committed
Raise error when used with mkdocs material instant loading feature, closes #2
1 parent 8e26f26 commit c00d85d

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

mkdocs_print_site_plugin/plugin.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from mkdocs.structure.files import File
1010
from mkdocs.structure.pages import Page
1111
from mkdocs.utils import write_file
12+
from mkdocs.exceptions import ConfigurationError
1213

1314
from mkdocs_print_site_plugin.renderer import Renderer
1415

@@ -38,6 +39,13 @@ def on_config(self, config, **kwargs):
3839
"[mkdocs-print-site] 'print-site' should be defined as the *last* plugin, to ensure the print page has any changes other plugins make. Please update the 'plugins:' section in your mkdocs.yml"
3940
)
4041

42+
# Raise error when using instant loading
43+
if "features" in config.get("theme"):
44+
if "instant" in config.get("theme")["features"]:
45+
raise ConfigurationError(
46+
"[mkdocs-print-site] plugin is not compatible with instant loading. Remove the theme feature 'instant' in your mkdocs.yml file, or disable this plugin."
47+
)
48+
4149
# Create the (empty) print page file in temp directory
4250
tmp_dir = tempfile.gettempdir()
4351
tmp_path = os.path.join(tmp_dir, "print_page.md")
@@ -63,7 +71,9 @@ def on_config(self, config, **kwargs):
6371
# Warn if we don't have CSS styles corresponding to current theme
6472
theme_name = config.get("theme").name
6573
theme_css_files = [Path(f).stem for f in os.listdir(CSS_DIR)]
66-
theme_css_files = [f[11:] for f in theme_css_files if f != 'print_site'] # remove 'print-site' prefix
74+
theme_css_files = [
75+
f[11:] for f in theme_css_files if f != "print_site"
76+
] # remove 'print-site' prefix
6777
if theme_name not in theme_css_files:
6878
logging.warning(
6979
"[mkdocs-print-site] Theme %s not yet supported, which means print margins and page breaks might be off."
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
site_name: Test
2+
3+
theme:
4+
name: material
5+
features:
6+
- instant
7+
palette:
8+
scheme: slate
9+
10+
plugins:
11+
- print-site
12+
13+
nav:
14+
- Home: index.md
15+
- Page Z: z.md
16+
- Page A: a.md

tests/test_building.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ def text_in_page(tmp_proj, page_path, text):
114114
#### Tests ####
115115

116116

117+
def test_instant_loading_gives_error(tmp_path):
118+
check_build(tmp_path, "basic/mkdocs_material_instant_loading.yml", exit_code=1)
119+
120+
117121
def test_no_toc(tmp_path):
118122
prj_path = check_build(tmp_path, "basic/mkdocs_no_toc.yml")
119123

0 commit comments

Comments
 (0)