clean: rename bulk_album category

This commit is contained in:
2025-07-07 23:03:48 +02:00
parent a980dd8ead
commit 67a83708cf
7 changed files with 49 additions and 49 deletions

View File

@ -10,21 +10,21 @@ if TYPE_CHECKING:
from path import Path
env = Environment(loader=FileSystemLoader('src/templates'))
album_template = env.get_template('bulk_album.jinja')
category_template = env.get_template('bulk_category.jinja')
class BulkAlbum():
class BulkCategory():
def __init__(self, name: str, albums_path: Path, pictures: list[Picture] = None, is_repertoried: bool = False):
def __init__(self, name: str, categorys_path: Path, pictures: list[Picture] = None, is_repertoried: bool = False):
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(categorys_path, f"{name}.html")
def add_picture(self, picture: Picture) -> None:
self._pictures.append(picture)
def _to_html(self) -> str|None:
html_rendered = album_template.render(album=self)
html_rendered = category_template.render(category=self)
return html_rendered
def create(self) -> Path:

View File

@ -17,7 +17,7 @@ page_template = env.get_template('bulk_page.jinja')
class BulkPage():
def __init__(self, path: Path, name: str, pictures: list[Picture] = None, prev: Page|None = None, next: Page|None = None):
def __init__(self, path: Path, name: str, pictures: list[Picture] = None, prev: BulkPage|None = None, next: BulkPage|None = None):
self.name: str = name
self._path: Path = path
self._pictures: list[Picture] = pictures or []

View File

@ -1,4 +1,4 @@
CREATE_GENERAL_ALBUM: bool = True
CREATE_GENERAL_CATEGORY: bool = True
THUMB_DIMENSION: tuple[int, int] = (200, 200)

View File

@ -5,7 +5,7 @@ from progress.bar import Bar
from path import Path
from picture import Picture
from bulk_page import BulkPage
from bulk_album import BulkAlbum
from bulk_category import BulkCategory
import argparse
import config
@ -57,45 +57,45 @@ def create_pages(pages: list[BulkPage]) -> None:
page.create()
bar.next()
def scan_albums(pages: list[BulkPage], albums_path: Path) -> list[BulkAlbum]:
albums: dict[str, BulkAlbum] = {}
def scan_categories(pages: list[BulkPage], categories_path: Path) -> list[BulkCategory]:
categories: dict[str, BulkCategory] = {}
with Bar("Scanning pages...", max=len(pages)) as bar:
for page in pages:
for picture in page.get_pictures():
for album_name in picture.get_albums_name():
album: BulkAlbum | None = albums.get(album_name)
if (album is None):
album = BulkAlbum(album_name, albums_path)
albums.update({album_name: album})
picture.albums.append(album)
album.add_picture(picture)
for category_name in picture.get_categories_name():
category: BulkCategory | None = categories.get(category_name)
if (category is None):
category = BulkCategory(category_name, categories_path)
categories.update({category_name: category})
picture.categories.append(category)
category.add_picture(picture)
bar.next()
return (albums.values())
return (categories.values())
def create_albums(albums: list[BulkAlbum]) -> None:
with Bar("Generating albums...", max=len(albums)) as bar:
for album in albums:
album.create()
def create_categories(categories: list[BulkCategory]) -> None:
with Bar("Generating categories...", max=len(categories)) as bar:
for category in categories:
category.create()
bar.next()
def gen_bulk(bulk_path: Path):
album_path: Path = Path(bulk_path, "albums")
category_path: Path = Path(bulk_path, "categories")
pages: list[BulkPage] = scan_pages(bulk_path.get_dirs())
albums: list[BulkAlbum] = scan_albums(pages, album_path)
categories: list[BulkCategory] = scan_categories(pages, category_path)
if config.CREATE_GENERAL_ALBUM:
for album in albums:
if (album.name == "general"):
album.path = Path(bulk_path, "index.html")
if config.CREATE_GENERAL_CATEGORY:
for category in categories:
if (category.name == "general"):
category.path = Path(bulk_path, "index.html")
Path("./src/templates/bulk_page.css").copy_to(Path(bulk_path, "bulk_page.css"))
create_pages(pages)
Path("./src/templates/bulk_album.css").copy_to(Path(bulk_path, "bulk_album.css"))
if (not album_path.exist()):
album_path.create()
create_albums(albums)
Path("./src/templates/bulk_category.css").copy_to(Path(bulk_path, "bulk_category.css"))
if (not category_path.exist()):
category_path.create()
create_categories(categories)
def regen(bulk_path: Path, is_thumb: bool, is_small: bool):

View File

@ -11,7 +11,7 @@ import config
if TYPE_CHECKING:
from bulk_page import BulkPage
from bulk_album import Album
from bulk_category import BulkCategory
class Picture():
def __init__(self, picture_path: Path, id: int, page: BulkPage = None, raw: Path|None = None, is_repertoried: bool = True):
@ -19,21 +19,21 @@ class Picture():
self._small: Path = Path(picture_path.get_absolute_path()[:-4] + "_small.jpg")
self._thumb: Path = Path(picture_path.get_absolute_path()[:-4] + "_thumb.jpg")
self._profile_file: Path = Path(picture_path.get_absolute_path() + ".out.pp3")
self._albums_file: Path = Path(picture_path.get_absolute_path()[:-4] + "_albums.txt")
self._categories_file: Path = Path(picture_path.get_absolute_path()[:-4] + "_categories.txt")
self._raw: Path|None = raw
self.id: int = id
self._page: BulkPage = 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()
if (len(albums_name)):
self._albums_name += albums_name.split("\n")
self._categories_name: list[str] = []
self.categories: list[BulkCategory] = []
if self._categories_file.exist():
with open(self._categories_file.get_absolute_path(), "r+") as f:
categories_name: list[str] = f.read()
if (len(categories_name)):
self._categories_name += categories_name.split("\n")
else:
self._albums_file.touch()
if (config.CREATE_GENERAL_ALBUM):
self._albums_name.append("general")
self._categories_file.touch()
if (config.CREATE_GENERAL_CATEGORY):
self._categories_name.append("general")
self._is_reperoried: bool = is_repertoried
self.get_small()
self.get_thumb()
@ -41,8 +41,8 @@ class Picture():
def get_page(self):
return self._page
def get_albums_name(self):
return self._albums_name
def get_categories_name(self):
return self._categories_name
def get_small(self):
if not self._small.exist():

View File

@ -2,13 +2,13 @@
<html>
<head>
<link rel="stylesheet" href="/bulk/bulk_album.css">
<link rel="stylesheet" href="/bulk/bulk_category.css">
</head>
<body>
<h1>{{ album.name }}</h1>
<h1>{{ category.name }}</h1>
<div class="picture-container">
{% for picture in album._pictures %}
{% for picture in category._pictures %}
<a href="{{ picture.get_page().html.get_url() }}#{{ picture.id }}">
<img src="{{ picture.get_thumb().get_url() }}">
</a>