Skip to content

Commit

Permalink
Merge pull request #2 from FeldrinH/main
Browse files Browse the repository at this point in the history
Register generated zip files with MkDocs
  • Loading branch information
JakubAndrysek authored Jan 22, 2025
2 parents d84957d + 4e5f2d9 commit a0a2180
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion zip_folders/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,33 @@
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=[])),
('debug', config_options.Type(bool, default=False)),
('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']

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'
Expand Down

0 comments on commit a0a2180

Please sign in to comment.