From 4df248b18f067bfc28725f4c153790e53d658cbb Mon Sep 17 00:00:00 2001 From: Bart van Woesik Date: Wed, 11 Sep 2024 20:58:31 +0200 Subject: [PATCH] add hooks to position offset plugin check --- mkdocs_print_site_plugin/plugin.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mkdocs_print_site_plugin/plugin.py b/mkdocs_print_site_plugin/plugin.py index 51f7f1a..83029ab 100644 --- a/mkdocs_print_site_plugin/plugin.py +++ b/mkdocs_print_site_plugin/plugin.py @@ -63,7 +63,15 @@ def on_config(self, config, **kwargs): # it is important 'print-site' is defined last in the 'plugins' plugins = config.get("plugins") print_site_position = [*dict(plugins)].index("print-site") - if print_site_position != len(plugins) - 1: + + # Offset begins at 1 due to indexing starting at 0 + position_offset = 1 + + # Check if 'hooks' is defined in the 'plugins' section + if isinstance(config.get("hooks"), dict): + position_offset += len(config.get("hooks")) + + if print_site_position != len(plugins) - position_offset: msg = "[mkdocs-print-site] 'print-site' should be defined as the *last* plugin," msg += "to ensure the print page has any changes other plugins make." msg += "Please update the 'plugins:' section in your mkdocs.yml"