From 92089c67f1eeccb390302dbd59e849ecd82fd8b1 Mon Sep 17 00:00:00 2001 From: squidfunk Date: Mon, 14 Oct 2024 14:41:35 +0200 Subject: [PATCH] Fixed race condition in privacy plugin --- material/plugins/privacy/plugin.py | 12 +++++++----- src/plugins/privacy/plugin.py | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/material/plugins/privacy/plugin.py b/material/plugins/privacy/plugin.py index 5d2e9934fde..7dd2cc55002 100644 --- a/material/plugins/privacy/plugin.py +++ b/material/plugins/privacy/plugin.py @@ -96,11 +96,9 @@ def on_files(self, files, *, config): # automatically loads Mermaid.js when a Mermaid diagram is # found in the page - https://bit.ly/36tZXsA. if "mermaid.min.js" in url.path and not config.site_url: - path = url.geturl() - if path not in config.extra_javascript: - config.extra_javascript.append( - ExtraScriptValue(path) - ) + script = ExtraScriptValue(url.geturl()) + if script not in config.extra_javascript: + config.extra_javascript.append(script) # The local asset references at least one external asset, which # means we must download and replace them later @@ -149,6 +147,10 @@ def on_page_content(self, html, *, page, config, files): if not self._is_excluded(url, page.file): self._queue(url, config, concurrent = True) + # Sync all concurrent jobs + def on_env(self, env, *, config, files): + wait(self.pool_jobs) + # Process external assets in template (run later) @event_priority(-50) def on_post_template(self, output_content, *, template_name, config): diff --git a/src/plugins/privacy/plugin.py b/src/plugins/privacy/plugin.py index 5d2e9934fde..7dd2cc55002 100644 --- a/src/plugins/privacy/plugin.py +++ b/src/plugins/privacy/plugin.py @@ -96,11 +96,9 @@ def on_files(self, files, *, config): # automatically loads Mermaid.js when a Mermaid diagram is # found in the page - https://bit.ly/36tZXsA. if "mermaid.min.js" in url.path and not config.site_url: - path = url.geturl() - if path not in config.extra_javascript: - config.extra_javascript.append( - ExtraScriptValue(path) - ) + script = ExtraScriptValue(url.geturl()) + if script not in config.extra_javascript: + config.extra_javascript.append(script) # The local asset references at least one external asset, which # means we must download and replace them later @@ -149,6 +147,10 @@ def on_page_content(self, html, *, page, config, files): if not self._is_excluded(url, page.file): self._queue(url, config, concurrent = True) + # Sync all concurrent jobs + def on_env(self, env, *, config, files): + wait(self.pool_jobs) + # Process external assets in template (run later) @event_priority(-50) def on_post_template(self, output_content, *, template_name, config):