Skip to content

Commit

Permalink
Merge pull request #5 from Sewer56/fix-serve-rebuild
Browse files Browse the repository at this point in the history
Fix: Disabling while in 'serve' mode after first run
  • Loading branch information
JonasDoesThings authored Jun 9, 2024
2 parents c4defb9 + 39f7148 commit bfe1eb8
Showing 1 changed file with 8 additions and 6 deletions.
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

0 comments on commit bfe1eb8

Please sign in to comment.