only write the static files once
This commit is contained in:
@@ -892,7 +892,7 @@ class Gallery:
|
|||||||
if self.settings["write_html"]:
|
if self.settings["write_html"]:
|
||||||
album_writer = AlbumPageWriter(self.settings, index_title=self.title)
|
album_writer = AlbumPageWriter(self.settings, index_title=self.title)
|
||||||
album_list_writer = AlbumListPageWriter(
|
album_list_writer = AlbumListPageWriter(
|
||||||
self.settings, index_title=self.title
|
self.settings, index_title=self.title, copy_files=False
|
||||||
)
|
)
|
||||||
with progressbar(
|
with progressbar(
|
||||||
self.albums.values(),
|
self.albums.values(),
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class PageWriter(AbstractWriter):
|
|||||||
def generate_media_pages(gallery):
|
def generate_media_pages(gallery):
|
||||||
"""Generates and writes the media pages for all media in the 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():
|
for album in gallery.albums.values():
|
||||||
medias = album.medias
|
medias = album.medias
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ THEMES_PATH = os.path.normpath(
|
|||||||
class AbstractWriter:
|
class AbstractWriter:
|
||||||
template_file = None
|
template_file = None
|
||||||
|
|
||||||
def __init__(self, settings, index_title=""):
|
def __init__(self, settings, index_title="", copy_files=True):
|
||||||
self.settings = settings
|
self.settings = settings
|
||||||
self.output_dir = settings["destination"]
|
self.output_dir = settings["destination"]
|
||||||
self.theme = settings["theme"]
|
self.theme = settings["theme"]
|
||||||
@@ -95,33 +95,34 @@ class AbstractWriter:
|
|||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Copy the theme files in the output dir
|
|
||||||
self.theme_path = os.path.join(self.output_dir, "static")
|
self.theme_path = os.path.join(self.output_dir, "static")
|
||||||
if os.path.isdir(self.theme_path):
|
if copy_files:
|
||||||
shutil.rmtree(self.theme_path)
|
# Copy the theme files in the output dir
|
||||||
|
if os.path.isdir(self.theme_path):
|
||||||
|
shutil.rmtree(self.theme_path)
|
||||||
|
|
||||||
for static_path in (
|
for static_path in (
|
||||||
os.path.join(THEMES_PATH, "default", "static"),
|
os.path.join(THEMES_PATH, "default", "static"),
|
||||||
os.path.join(self.theme, "static"),
|
os.path.join(self.theme, "static"),
|
||||||
):
|
):
|
||||||
shutil.copytree(static_path, self.theme_path, dirs_exist_ok=True)
|
shutil.copytree(static_path, self.theme_path, dirs_exist_ok=True)
|
||||||
|
|
||||||
# Ensure that the theme dir is writeable
|
# Ensure that the theme dir is writeable
|
||||||
for root, _, files in os.walk(self.theme_path):
|
for root, _, files in os.walk(self.theme_path):
|
||||||
st = os.stat(root)
|
st = os.stat(root)
|
||||||
os.chmod(root, st.st_mode | stat.S_IWUSR)
|
os.chmod(root, st.st_mode | stat.S_IWUSR)
|
||||||
for name in files:
|
for name in files:
|
||||||
path = os.path.join(root, name)
|
path = os.path.join(root, name)
|
||||||
st = os.stat(path)
|
st = os.stat(path)
|
||||||
os.chmod(path, st.st_mode | stat.S_IWUSR)
|
os.chmod(path, st.st_mode | stat.S_IWUSR)
|
||||||
|
|
||||||
if self.settings["user_css"]:
|
if self.settings["user_css"]:
|
||||||
if not os.path.exists(self.settings["user_css"]):
|
if not os.path.exists(self.settings["user_css"]):
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
"CSS file %s could not be found", self.settings["user_css"]
|
"CSS file %s could not be found", self.settings["user_css"]
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
shutil.copy(self.settings["user_css"], self.theme_path)
|
shutil.copy(self.settings["user_css"], self.theme_path)
|
||||||
|
|
||||||
def generate_context(self, album):
|
def generate_context(self, album):
|
||||||
"""Generate the context dict for the given path."""
|
"""Generate the context dict for the given path."""
|
||||||
|
|||||||
Reference in New Issue
Block a user