Skip to content

Commit

Permalink
Merge self.config.enabled and self.disabled_by_serve into `self.i…
Browse files Browse the repository at this point in the history
…s_enabled`.
  • Loading branch information
Sewer56 committed Jun 9, 2024
1 parent b60c5c1 commit 83e4239
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions mkdocs_exclude_unused_files/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,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.disabled_by_serve = True
self.is_enabled = False
return
else:
self.disabled_by_serve = False

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 @@ -101,7 +100,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 or self.disabled_by_serve:
if not self.is_enabled:
log.debug("exclude-unused-files plugin disabled")
return None

Expand All @@ -127,7 +126,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 or self.disabled_by_serve:
if not self.is_enabled:
log.debug("exclude-unused-files plugin disabled")
return None

Expand Down Expand Up @@ -165,7 +164,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 or self.disabled_by_serve:
if not self.is_enabled:
log.debug("exclude-unused-files plugin disabled")
return None

Expand All @@ -191,4 +190,4 @@ def on_post_build(self, config: MkDocsConfig) -> None:
except OSError as error:
log.warning("failed deleting file %s, an error occurred %s", str(error.filename), error.strerror)

log.info("deleted %s unused assets from final output", str(delete_count))
log.info("deleted %s unused assets from final output", str(delete_count))

0 comments on commit 83e4239

Please sign in to comment.