Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Disabling while in 'serve' mode after first run #5

Merged
merged 3 commits into from
Jun 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions mkdocs_exclude_unused_files/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,17 @@ class ExcludeUnusedFilesPlugin(BasePlugin[ExcludeUnusedFilesPluginConfig]):

@mkdocs.plugins.event_priority(-100)
def on_startup(self, *, command, dirty) -> None:
if not self.config.enabled:
self.is_enabled = self.config.enabled
if not self.is_enabled:
log.debug("exclude-unused-files plugin disabled")
return
# Disable plugin when the documentation is served, i.e., "mkdocs serve" is used
if command == "serve" and not self.config.enabled_on_serve:
log.debug("exclude-unused-files plugin disabled while MkDocs is running in 'serve' mode.")
self.config.enabled = False
self.is_enabled = False
return

if self.config.enabled:
if self.is_enabled:
if self.config.file_types_override_mode == "append" and self.config.file_types_to_check != []:
log.debug("extending default file_types_to_check: %s", ", ".join(self.config.file_types_to_check))
self.file_types_to_check.extend(self.config.file_types_to_check)
Expand All @@ -99,7 +101,7 @@ def on_startup(self, *, command, dirty) -> None:

@mkdocs.plugins.event_priority(-100)
def on_files(self, files: Files, config: MkDocsConfig) -> Optional[Files]:
if not self.config.enabled:
if not self.is_enabled:
log.debug("exclude-unused-files plugin disabled")
return None

Expand All @@ -125,7 +127,7 @@ def on_files(self, files: Files, config: MkDocsConfig) -> Optional[Files]:

@mkdocs.plugins.event_priority(-100)
def on_post_page(self, output: str, page: Page, config: MkDocsConfig) -> Optional[str]:
if not self.config.enabled:
if not self.is_enabled:
log.debug("exclude-unused-files plugin disabled")
return None

Expand Down Expand Up @@ -163,7 +165,7 @@ def on_post_page(self, output: str, page: Page, config: MkDocsConfig) -> Optiona
return output

def on_post_build(self, config: MkDocsConfig) -> None:
if not self.config.enabled:
if not self.is_enabled:
log.debug("exclude-unused-files plugin disabled")
return None

Expand Down
Loading