From 5a5d78cb1d573f418198bcc95a1f903cfb9c2928 Mon Sep 17 00:00:00 2001 From: Juhan Oskar Hennoste Date: Sun, 8 Dec 2024 18:30:09 +0200 Subject: [PATCH 1/2] Register generated zip files with mkdocs --- zip_folders/plugin.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/zip_folders/plugin.py b/zip_folders/plugin.py index 63fa61f..66365a2 100644 --- a/zip_folders/plugin.py +++ b/zip_folders/plugin.py @@ -17,6 +17,11 @@ log: logging.Logger = logging.getLogger("mkdocs") +class PlaceholderFile(File): + def copy_file(self, *args, **kwargs): + pass + + class ZipFoldersPlugin(BasePlugin): config_scheme = ( ('folders', config_options.Type(list, default=[])), @@ -24,6 +29,14 @@ class ZipFoldersPlugin(BasePlugin): ('hash_extension', config_options.Type(str, default='.zip.hash')), ) + def on_files(self, files, config): + folders = self.config['folders'] + + for folder in folders: + files.append(PlaceholderFile.generated( + config, f'{folder}.zip', abs_src_path=os.path.join(config['site_dir'], f'{folder}.zip') + )) + def on_post_build(self, config): folders = self.config['folders'] From 4e5f2d9147c8f124632562ffac6f684be8fdfbe8 Mon Sep 17 00:00:00 2001 From: Juhan Oskar Hennoste Date: Sun, 8 Dec 2024 18:30:21 +0200 Subject: [PATCH 2/2] Turn missing folder message into a warning --- zip_folders/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zip_folders/plugin.py b/zip_folders/plugin.py index 66365a2..72dd5ca 100644 --- a/zip_folders/plugin.py +++ b/zip_folders/plugin.py @@ -43,7 +43,7 @@ def on_post_build(self, config): for folder in folders: path = os.path.join(config['site_dir'], folder) if not os.path.exists(path): - print(f"The folder {folder} does not exist.") + log.warning(f"The folder {folder} does not exist.") continue zip_path = f'{path}.zip'