clean: rename bulk_album category
This commit is contained in:
@ -10,21 +10,21 @@ if TYPE_CHECKING:
|
|||||||
from path import Path
|
from path import Path
|
||||||
|
|
||||||
env = Environment(loader=FileSystemLoader('src/templates'))
|
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.name: str = name
|
||||||
self._pictures: list[Picture] = pictures or []
|
self._pictures: list[Picture] = pictures or []
|
||||||
self._is_repertoried: bool = is_repertoried
|
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:
|
def add_picture(self, picture: Picture) -> None:
|
||||||
self._pictures.append(picture)
|
self._pictures.append(picture)
|
||||||
|
|
||||||
def _to_html(self) -> str|None:
|
def _to_html(self) -> str|None:
|
||||||
html_rendered = album_template.render(album=self)
|
html_rendered = category_template.render(category=self)
|
||||||
return html_rendered
|
return html_rendered
|
||||||
|
|
||||||
def create(self) -> Path:
|
def create(self) -> Path:
|
@ -17,7 +17,7 @@ page_template = env.get_template('bulk_page.jinja')
|
|||||||
|
|
||||||
class BulkPage():
|
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.name: str = name
|
||||||
self._path: Path = path
|
self._path: Path = path
|
||||||
self._pictures: list[Picture] = pictures or []
|
self._pictures: list[Picture] = pictures or []
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
|
|
||||||
CREATE_GENERAL_ALBUM: bool = True
|
CREATE_GENERAL_CATEGORY: bool = True
|
||||||
THUMB_DIMENSION: tuple[int, int] = (200, 200)
|
THUMB_DIMENSION: tuple[int, int] = (200, 200)
|
50
src/main.py
50
src/main.py
@ -5,7 +5,7 @@ from progress.bar import Bar
|
|||||||
from path import Path
|
from path import Path
|
||||||
from picture import Picture
|
from picture import Picture
|
||||||
from bulk_page import BulkPage
|
from bulk_page import BulkPage
|
||||||
from bulk_album import BulkAlbum
|
from bulk_category import BulkCategory
|
||||||
import argparse
|
import argparse
|
||||||
import config
|
import config
|
||||||
|
|
||||||
@ -57,45 +57,45 @@ def create_pages(pages: list[BulkPage]) -> None:
|
|||||||
page.create()
|
page.create()
|
||||||
bar.next()
|
bar.next()
|
||||||
|
|
||||||
def scan_albums(pages: list[BulkPage], albums_path: Path) -> list[BulkAlbum]:
|
def scan_categories(pages: list[BulkPage], categories_path: Path) -> list[BulkCategory]:
|
||||||
albums: dict[str, BulkAlbum] = {}
|
categories: dict[str, BulkCategory] = {}
|
||||||
with Bar("Scanning pages...", max=len(pages)) as bar:
|
with Bar("Scanning pages...", max=len(pages)) as bar:
|
||||||
for page in pages:
|
for page in pages:
|
||||||
for picture in page.get_pictures():
|
for picture in page.get_pictures():
|
||||||
for album_name in picture.get_albums_name():
|
for category_name in picture.get_categories_name():
|
||||||
album: BulkAlbum | None = albums.get(album_name)
|
category: BulkCategory | None = categories.get(category_name)
|
||||||
if (album is None):
|
if (category is None):
|
||||||
album = BulkAlbum(album_name, albums_path)
|
category = BulkCategory(category_name, categories_path)
|
||||||
albums.update({album_name: album})
|
categories.update({category_name: category})
|
||||||
picture.albums.append(album)
|
picture.categories.append(category)
|
||||||
album.add_picture(picture)
|
category.add_picture(picture)
|
||||||
bar.next()
|
bar.next()
|
||||||
return (albums.values())
|
return (categories.values())
|
||||||
|
|
||||||
def create_albums(albums: list[BulkAlbum]) -> None:
|
def create_categories(categories: list[BulkCategory]) -> None:
|
||||||
with Bar("Generating albums...", max=len(albums)) as bar:
|
with Bar("Generating categories...", max=len(categories)) as bar:
|
||||||
for album in albums:
|
for category in categories:
|
||||||
album.create()
|
category.create()
|
||||||
bar.next()
|
bar.next()
|
||||||
|
|
||||||
def gen_bulk(bulk_path: Path):
|
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())
|
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:
|
if config.CREATE_GENERAL_CATEGORY:
|
||||||
for album in albums:
|
for category in categories:
|
||||||
if (album.name == "general"):
|
if (category.name == "general"):
|
||||||
album.path = Path(bulk_path, "index.html")
|
category.path = Path(bulk_path, "index.html")
|
||||||
|
|
||||||
Path("./src/templates/bulk_page.css").copy_to(Path(bulk_path, "bulk_page.css"))
|
Path("./src/templates/bulk_page.css").copy_to(Path(bulk_path, "bulk_page.css"))
|
||||||
create_pages(pages)
|
create_pages(pages)
|
||||||
|
|
||||||
Path("./src/templates/bulk_album.css").copy_to(Path(bulk_path, "bulk_album.css"))
|
Path("./src/templates/bulk_category.css").copy_to(Path(bulk_path, "bulk_category.css"))
|
||||||
if (not album_path.exist()):
|
if (not category_path.exist()):
|
||||||
album_path.create()
|
category_path.create()
|
||||||
create_albums(albums)
|
create_categories(categories)
|
||||||
|
|
||||||
|
|
||||||
def regen(bulk_path: Path, is_thumb: bool, is_small: bool):
|
def regen(bulk_path: Path, is_thumb: bool, is_small: bool):
|
||||||
|
@ -11,7 +11,7 @@ import config
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from bulk_page import BulkPage
|
from bulk_page import BulkPage
|
||||||
from bulk_album import Album
|
from bulk_category import BulkCategory
|
||||||
|
|
||||||
class Picture():
|
class Picture():
|
||||||
def __init__(self, picture_path: Path, id: int, page: BulkPage = None, raw: Path|None = None, is_repertoried: bool = True):
|
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._small: Path = Path(picture_path.get_absolute_path()[:-4] + "_small.jpg")
|
||||||
self._thumb: Path = Path(picture_path.get_absolute_path()[:-4] + "_thumb.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._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._raw: Path|None = raw
|
||||||
self.id: int = id
|
self.id: int = id
|
||||||
self._page: BulkPage = page
|
self._page: BulkPage = page
|
||||||
self._albums_name: list[str] = []
|
self._categories_name: list[str] = []
|
||||||
self.albums: list[Album] = []
|
self.categories: list[BulkCategory] = []
|
||||||
if self._albums_file.exist():
|
if self._categories_file.exist():
|
||||||
with open(self._albums_file.get_absolute_path(), "r+") as f:
|
with open(self._categories_file.get_absolute_path(), "r+") as f:
|
||||||
albums_name: list[str] = f.read()
|
categories_name: list[str] = f.read()
|
||||||
if (len(albums_name)):
|
if (len(categories_name)):
|
||||||
self._albums_name += albums_name.split("\n")
|
self._categories_name += categories_name.split("\n")
|
||||||
else:
|
else:
|
||||||
self._albums_file.touch()
|
self._categories_file.touch()
|
||||||
if (config.CREATE_GENERAL_ALBUM):
|
if (config.CREATE_GENERAL_CATEGORY):
|
||||||
self._albums_name.append("general")
|
self._categories_name.append("general")
|
||||||
self._is_reperoried: bool = is_repertoried
|
self._is_reperoried: bool = is_repertoried
|
||||||
self.get_small()
|
self.get_small()
|
||||||
self.get_thumb()
|
self.get_thumb()
|
||||||
@ -41,8 +41,8 @@ class Picture():
|
|||||||
def get_page(self):
|
def get_page(self):
|
||||||
return self._page
|
return self._page
|
||||||
|
|
||||||
def get_albums_name(self):
|
def get_categories_name(self):
|
||||||
return self._albums_name
|
return self._categories_name
|
||||||
|
|
||||||
def get_small(self):
|
def get_small(self):
|
||||||
if not self._small.exist():
|
if not self._small.exist():
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" href="/bulk/bulk_album.css">
|
<link rel="stylesheet" href="/bulk/bulk_category.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<h1>{{ album.name }}</h1>
|
<h1>{{ category.name }}</h1>
|
||||||
<div class="picture-container">
|
<div class="picture-container">
|
||||||
{% for picture in album._pictures %}
|
{% for picture in category._pictures %}
|
||||||
<a href="{{ picture.get_page().html.get_url() }}#{{ picture.id }}">
|
<a href="{{ picture.get_page().html.get_url() }}#{{ picture.id }}">
|
||||||
<img src="{{ picture.get_thumb().get_url() }}">
|
<img src="{{ picture.get_thumb().get_url() }}">
|
||||||
</a>
|
</a>
|
Reference in New Issue
Block a user