diff --git a/src/album.py b/src/album.py index 515328a..c29ddf7 100644 --- a/src/album.py +++ b/src/album.py @@ -15,10 +15,10 @@ album_template = env.get_template('album.jinja') class Album(): def __init__(self, name: str, albums_path: Path, pictures: list[Picture] = None, is_repertoried: bool = False): - self._name: str = name + self.name: str = name self._pictures: list[Picture] = pictures or [] self._is_repertoried: bool = is_repertoried - self._path: Path = Path(albums_path, f"{name}.html") + self.path: Path = Path(albums_path, f"{name}.html") def add_picture(self, picture: Picture) -> None: self._pictures.append(picture) @@ -28,5 +28,5 @@ class Album(): return html_rendered def create(self) -> Path: - with open(self._path.get_absolute_path(), "w") as f: + with open(self.path.get_absolute_path(), "w") as f: f.write(self._to_html()) \ No newline at end of file diff --git a/src/main.py b/src/main.py index df61498..6f7b636 100644 --- a/src/main.py +++ b/src/main.py @@ -1,5 +1,4 @@ import sys -import shutil import os from progress.bar import Bar @@ -61,6 +60,7 @@ def scan_albums(pages: list[Page], albums_path: Path) -> list[Album]: if (album is None): album = Album(album_name, albums_path) albums.update({album_name: album}) + picture.albums.append(album) album.add_picture(picture) bar.next() return (albums.values()) @@ -72,17 +72,25 @@ def create_albums(albums: list[Album]) -> None: bar.next() def gen_bulk(bulk_path: Path): - pages: list[Page] = scan_pages(bulk_path.get_dirs()) - shutil.copy2("./src/templates/page.css", bulk_path.get_absolute_path()) - create_pages(pages) album_path: Path = Path(bulk_path, "albums") + + pages: list[Page] = scan_pages(bulk_path.get_dirs()) + albums: list[Album] = scan_albums(pages, album_path) + + if config.CREATE_GENERAL_ALBUM: + for album in albums: + if (album.name == "general"): + album.path = Path(bulk_path, "general.html") + + Path("./src/templates/page.css").copy_to(Path(bulk_path, "page.css")) + create_pages(pages) + + Path("./src/templates/album.css").copy_to(Path(bulk_path, "album.css")) if (not album_path.exist()): album_path.create() - albums: list[Album] = scan_albums(pages, album_path) create_albums(albums) - if config.CREATE_GENERAL_ALBUM: - shutil.move(os.path.join(album_path.get_absolute_path(), "general.html"), os.path.join(bulk_path.get_absolute_path(), "index.html")) - shutil.copy2("./src/templates/album.css", bulk_path.get_absolute_path()) + + def regen(bulk_path: Path, is_thumb: bool, is_small: bool): for page in scan_pages(bulk_path.get_dirs()): @@ -96,7 +104,7 @@ def regen(bulk_path: Path, is_thumb: bool, is_small: bool): def main(): args = argument_parsing() - bulk_path: Path = Path(args.site_path, "bulk") + bulk_path: Path = Path(args.site_path, "bulk/") if args.regen is not None: regen(bulk_path, 't' in args.regen, 's' in args.regen) gen_bulk(bulk_path) diff --git a/src/path.py b/src/path.py index a805973..630c4b1 100644 --- a/src/path.py +++ b/src/path.py @@ -2,7 +2,7 @@ from __future__ import annotations import os import sys - +import shutil class Path(): def __init__(self, *paths: str | Path): @@ -56,6 +56,9 @@ class Path(): files.append(path) return files + def copy_to(self, destination: Path) -> None: + shutil.copy2(self.get_absolute_path(), destination.get_absolute_path()) + def __str__(self): return self._absolute_path diff --git a/src/picture.py b/src/picture.py index f3ec3c0..5f4cea9 100644 --- a/src/picture.py +++ b/src/picture.py @@ -23,6 +23,7 @@ class Picture(): self._raw: Path|None = raw self._page: Page = page self._albums_name: list[str] = [] + self.albums: list[Album] = [] if self._albums_file.exist(): with open(self._albums_file.get_absolute_path(), "r+") as f: albums_name: list[str] = f.read() diff --git a/src/templates/album.jinja b/src/templates/album.jinja index d4d45af..9f77af4 100644 --- a/src/templates/album.jinja +++ b/src/templates/album.jinja @@ -6,7 +6,7 @@
-