From a148592a2fad71a5183e7ec2ca195f9117ae357e Mon Sep 17 00:00:00 2001 From: David Schultz Date: Mon, 19 Feb 2024 17:59:00 -0600 Subject: [PATCH] only write the static files once --- src/sigal/gallery.py | 2 +- src/sigal/plugins/media_page.py | 2 +- src/sigal/writer.py | 49 +++++++++++++++++---------------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/sigal/gallery.py b/src/sigal/gallery.py index f9eefa0..0d0d925 100644 --- a/src/sigal/gallery.py +++ b/src/sigal/gallery.py @@ -892,7 +892,7 @@ class Gallery: if self.settings["write_html"]: album_writer = AlbumPageWriter(self.settings, index_title=self.title) album_list_writer = AlbumListPageWriter( - self.settings, index_title=self.title + self.settings, index_title=self.title, copy_files=False ) with progressbar( self.albums.values(), diff --git a/src/sigal/plugins/media_page.py b/src/sigal/plugins/media_page.py index 5234bd3..3e2bcc1 100644 --- a/src/sigal/plugins/media_page.py +++ b/src/sigal/plugins/media_page.py @@ -71,7 +71,7 @@ class PageWriter(AbstractWriter): def generate_media_pages(gallery): """Generates and writes the media pages for all media in the gallery""" - writer = PageWriter(gallery.settings, index_title=gallery.title) + writer = PageWriter(gallery.settings, index_title=gallery.title, copy_files=False) for album in gallery.albums.values(): medias = album.medias diff --git a/src/sigal/writer.py b/src/sigal/writer.py index 4a8dd9d..1ab7c48 100644 --- a/src/sigal/writer.py +++ b/src/sigal/writer.py @@ -42,7 +42,7 @@ THEMES_PATH = os.path.normpath( class AbstractWriter: template_file = None - def __init__(self, settings, index_title=""): + def __init__(self, settings, index_title="", copy_files=True): self.settings = settings self.output_dir = settings["destination"] self.theme = settings["theme"] @@ -95,33 +95,34 @@ class AbstractWriter: ) sys.exit(1) - # Copy the theme files in the output dir self.theme_path = os.path.join(self.output_dir, "static") - if os.path.isdir(self.theme_path): - shutil.rmtree(self.theme_path) + if copy_files: + # Copy the theme files in the output dir + if os.path.isdir(self.theme_path): + shutil.rmtree(self.theme_path) - for static_path in ( - os.path.join(THEMES_PATH, "default", "static"), - os.path.join(self.theme, "static"), - ): - shutil.copytree(static_path, self.theme_path, dirs_exist_ok=True) + for static_path in ( + os.path.join(THEMES_PATH, "default", "static"), + os.path.join(self.theme, "static"), + ): + shutil.copytree(static_path, self.theme_path, dirs_exist_ok=True) - # Ensure that the theme dir is writeable - for root, _, files in os.walk(self.theme_path): - st = os.stat(root) - os.chmod(root, st.st_mode | stat.S_IWUSR) - for name in files: - path = os.path.join(root, name) - st = os.stat(path) - os.chmod(path, st.st_mode | stat.S_IWUSR) + # Ensure that the theme dir is writeable + for root, _, files in os.walk(self.theme_path): + st = os.stat(root) + os.chmod(root, st.st_mode | stat.S_IWUSR) + for name in files: + path = os.path.join(root, name) + st = os.stat(path) + os.chmod(path, st.st_mode | stat.S_IWUSR) - if self.settings["user_css"]: - if not os.path.exists(self.settings["user_css"]): - self.logger.error( - "CSS file %s could not be found", self.settings["user_css"] - ) - else: - shutil.copy(self.settings["user_css"], self.theme_path) + if self.settings["user_css"]: + if not os.path.exists(self.settings["user_css"]): + self.logger.error( + "CSS file %s could not be found", self.settings["user_css"] + ) + else: + shutil.copy(self.settings["user_css"], self.theme_path) def generate_context(self, album): """Generate the context dict for the given path."""