clean: remove bulk_suffix

bulk_page -> page
bulk_category -> category
page -> collection
This commit is contained in:
2025-07-09 01:57:52 +02:00
parent cbab99cc82
commit 74e99b96f0
17 changed files with 304 additions and 298 deletions

View File

@ -1,78 +0,0 @@
from __future__ import annotations
from jinja2 import Environment, FileSystemLoader
import photodown
import os
from path import Path
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from bulk_page import Page
from picture import Picture
env = Environment(loader=FileSystemLoader('src/templates'))
page_template = env.get_template('bulk_page.jinja')
class BulkPage():
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 []
self._exif: Path = Path(self._path, "exif.txt")
self._readme: Path = Path(self._path, "readme.md")
self._raw: Path = Path(self._path, name + ".NEF")
self.html: Path = Path(self._path, "page.html")
self.prev: Page = prev
self.next: Page = next
if (not self._readme.exist()):
self._readme.touch()
def add_picture(self, picture: Picture) -> None:
self._pictures.append(picture)
def get_pictures(self) -> list[Picture]:
return self._pictures
def _to_html(self) -> str|None:
html_rendered = page_template.render(page=self)
return html_rendered
def create(self) -> Path:
with open(self.html.get_absolute_path(), "w") as f:
f.write(self._to_html())
def render_readme(self) -> str|None:
if not self._readme.exist():
return None
with open(self._readme.get_absolute_path(), 'r') as f:
text = f.read()
if len(text) == 0:
return None
html = photodown.markdown(text)
return html
def _gen_exif(self):
if self._raw.exist():
if os.system(f"exiftool {self._raw.get_absolute_path()} > {self._exif.get_absolute_path()} 2>/dev/null") == 0:
return 0
os.remove(self._exif.get_absolute_path())
return 1
def get_exif(self) -> Path | None:
if not self._exif.exist():
if (self._gen_exif()):
return None
return self._exif
def render_exif(self):
if not self.get_exif():
return None
with open(self._exif.get_absolute_path()) as f:
return f.read()
def get_raw(self):
return self._raw

View File

@ -10,9 +10,9 @@ if TYPE_CHECKING:
from path import Path
env = Environment(loader=FileSystemLoader('src/templates'))
category_template = env.get_template('bulk_category.jinja')
category_template = env.get_template('category.jinja')
class BulkCategory():
class Category():
def __init__(self, name: str, categorys_path: Path, pictures: list[Picture] = None, is_repertoried: bool = False):
self.name: str = name

35
src/collection.py Normal file
View File

@ -0,0 +1,35 @@
from __future__ import annotations
from typing import TYPE_CHECKING
import config
from path import Path
if TYPE_CHECKING:
from photodown import Photodown
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('src/templates'))
page_template = env.get_template('collection.jinja')
class Collection:
def __init__(self, path: Path, markdown: Photodown):
self._path: Path = path
self._html: Path = Path(self._path.get_absolute_path()[:-len(config.COLLECTION_EXT)] + ".html")
self._markdown: Photodown = markdown
with open(path.get_absolute_path(), "r") as f:
self._raw_content: str = f.read()
def _get_content(self):
content = self._markdown.render(self._raw_content)
return content
def _to_html(self) -> str:
html: str = page_template.render(content=self._get_content())
return html
def create(self) -> Path:
with open(self._html.get_absolute_path(), "w") as f:
f.write(self._to_html())

View File

@ -3,4 +3,4 @@
CREATE_GENERAL_CATEGORY: bool = True
THUMB_DIMENSION: tuple[int, int] = (200, 200)
MAX_THREADS: int = 50
PAGE_EXT: str = ".ph"
COLLECTION_EXT: str = ".ph"

View File

@ -2,9 +2,9 @@ from progress.bar import Bar
from path import Path
from picture import Picture
from bulk_page import BulkPage
from bulk_category import BulkCategory
from page import Page
from category import Category
from collection import Collection
from photodown import Photodown
import argparse
@ -22,14 +22,14 @@ def argument_parsing():
args = parser.parse_args()
return args
def scan_bulk_pages(folders: list[Path]) -> list[BulkPage]:
pages: list[BulkPage] = []
prev: BulkPage = None
def scan_pages(folders: list[Path]) -> list[Page]:
pages: list[Page] = []
prev: Page = None
with Bar("Scanning Pages...", max=len(folders)) as bar:
for folder in folders:
files: list[Path] = folder.get_files()
page: BulkPage = BulkPage(folder, folder.get_name(), prev=prev)
page: Page = Page(folder, folder.get_name(), prev=prev)
raw: Path = Path(folder, folder.get_name() + ".NEF")
id: int = 0
@ -52,28 +52,28 @@ def scan_bulk_pages(folders: list[Path]) -> list[BulkPage]:
pages[0].prev = pages[-1]
return pages
def create_pages(pages: list[BulkPage]) -> None:
def create_pages(pages: list[Page]) -> None:
with Bar("Generating Pages...", max=len(pages)) as bar:
for page in pages:
page.create()
bar.next()
def scan_categories(pages: list[BulkPage], categories_path: Path) -> list[BulkCategory]:
categories: dict[str, BulkCategory] = {}
def scan_categories(pages: list[Page], categories_path: Path) -> list[Category]:
categories: dict[str, Category] = {}
with Bar("Scanning pages...", max=len(pages)) as bar:
for page in pages:
for picture in page.get_pictures():
for category_name in picture.get_categories_name():
category: BulkCategory | None = categories.get(category_name)
category: Category | None = categories.get(category_name)
if (category is None):
category = BulkCategory(category_name, categories_path)
category = Category(category_name, categories_path)
categories.update({category_name: category})
picture.categories.append(category)
category.add_picture(picture)
bar.next()
return (categories.values())
def create_categories(categories: list[BulkCategory]) -> None:
def create_categories(categories: list[Category]) -> None:
with Bar("Generating categories...", max=len(categories)) as bar:
for category in categories:
category.create()
@ -82,8 +82,8 @@ def create_categories(categories: list[BulkCategory]) -> None:
def gen_bulk(bulk_path: Path, markdown: Photodown):
category_path: Path = Path(bulk_path, "categories")
pages: list[BulkPage] = scan_bulk_pages(bulk_path.get_dirs())
categories: list[BulkCategory] = scan_categories(pages, category_path)
pages: list[Page] = scan_pages(bulk_path.get_dirs())
categories: list[Category] = scan_categories(pages, category_path)
bulk: list[Picture] = []
for page in pages:
@ -96,25 +96,25 @@ def gen_bulk(bulk_path: Path, markdown: Photodown):
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"))
Path("./src/templates/page.css").copy_to(Path(bulk_path, "page.css"))
create_pages(pages)
Path("./src/templates/bulk_category.css").copy_to(Path(bulk_path, "bulk_category.css"))
Path("./src/templates/category.css").copy_to(Path(bulk_path, "category.css"))
if (not category_path.exist()):
category_path.create()
create_categories(categories)
def scan_pages(site_path: Path, markdown: Photodown):
for path in [f for f in site_path.get_files() if f.get_name().endswith(config.PAGE_EXT)]:
page: Page = Page(path, markdown)
page.create()
def scan_collections(site_path: Path, markdown: Photodown):
for path in [f for f in site_path.get_files() if f.get_name().endswith(config.COLLECTION_EXT)]:
collection: Collection = Collection(path, markdown)
collection.create()
def gen_pages(site_path: Path, markdown: Photodown):
scan_pages(site_path, markdown)
Path("./src/templates/page.css").copy_to(Path(site_path, "page.css"))
def gen_collections(site_path: Path, markdown: Photodown):
scan_collections(site_path, markdown)
Path("./src/templates/collection.css").copy_to(Path(site_path, "collection.css"))
def regen(bulk_path: Path, is_thumb: bool, is_small: bool):
pages: list[BulkPage] = scan_bulk_pages(bulk_path.get_dirs())
def regen(_path: Path, is_thumb: bool, is_small: bool):
pages: list[Page] = scan_pages(_path.get_dirs())
with Bar("Regenerating assets...", max=len(pages)) as bar:
for page in pages:
for picture in page.get_pictures():
@ -140,7 +140,7 @@ def main():
regen(bulk_path, 't' in args.regen, 's' in args.regen)
markdown = Photodown()
gen_bulk(bulk_path, markdown)
gen_pages(site_path, markdown)
gen_collections(site_path, markdown)
gen_home(site_path)

View File

@ -1,34 +1,77 @@
from __future__ import annotations
from jinja2 import Environment, FileSystemLoader
import photodown
import os
from path import Path
from typing import TYPE_CHECKING
import config
from path import Path
if TYPE_CHECKING:
from photodown import Photodown
from jinja2 import Environment, FileSystemLoader
from picture import Picture
env = Environment(loader=FileSystemLoader('src/templates'))
page_template = env.get_template('page.jinja')
class Page:
def __init__(self, path: Path, markdown: Photodown):
class Page():
def __init__(self, path: Path, name: str, pictures: list[Picture] = None, prev: Page|None = None, next: Page|None = None):
self.name: str = name
self._path: Path = path
self._html: Path = Path(self._path.get_absolute_path()[:-len(config.PAGE_EXT)] + ".html")
self._markdown: Photodown = markdown
with open(path.get_absolute_path(), "r") as f:
self._raw_content: str = f.read()
self._pictures: list[Picture] = pictures or []
self._exif: Path = Path(self._path, "exif.txt")
self._readme: Path = Path(self._path, "readme.md")
self._raw: Path = Path(self._path, name + ".NEF")
self.html: Path = Path(self._path, "page.html")
self.prev: Page = prev
self.next: Page = next
if (not self._readme.exist()):
self._readme.touch()
def _get_content(self):
content = self._markdown.render(self._raw_content)
return content
def add_picture(self, picture: Picture) -> None:
self._pictures.append(picture)
def _to_html(self) -> str:
html: str = page_template.render(content=self._get_content())
return html
def get_pictures(self) -> list[Picture]:
return self._pictures
def _to_html(self) -> str|None:
html_rendered = page_template.render(page=self)
return html_rendered
def create(self) -> Path:
with open(self._html.get_absolute_path(), "w") as f:
with open(self.html.get_absolute_path(), "w") as f:
f.write(self._to_html())
def render_readme(self) -> str|None:
if not self._readme.exist():
return None
with open(self._readme.get_absolute_path(), 'r') as f:
text = f.read()
if len(text) == 0:
return None
html = photodown.markdown(text)
return html
def _gen_exif(self):
if self._raw.exist():
if os.system(f"exiftool {self._raw.get_absolute_path()} > {self._exif.get_absolute_path()} 2>/dev/null") == 0:
return 0
os.remove(self._exif.get_absolute_path())
return 1
def get_exif(self) -> Path | None:
if not self._exif.exist():
if (self._gen_exif()):
return None
return self._exif
def render_exif(self):
if not self.get_exif():
return None
with open(self._exif.get_absolute_path()) as f:
return f.read()
def get_raw(self):
return self._raw

View File

@ -10,11 +10,11 @@ from typing import TYPE_CHECKING
import config
if TYPE_CHECKING:
from bulk_page import BulkPage
from bulk_category import BulkCategory
from page import Page
from category import Category
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: Page = None, raw: Path|None = None, is_repertoried: bool = True):
self._large: Path = picture_path
self._small: Path = Path(picture_path.get_absolute_path()[:-4] + "_small.jpg")
self._thumb: Path = Path(picture_path.get_absolute_path()[:-4] + "_thumb.jpg")
@ -22,9 +22,9 @@ class Picture():
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._page: Page = page
self._categories_name: list[str] = []
self.categories: list[BulkCategory] = []
self.categories: list[Category] = []
if self._categories_file.exist():
with open(self._categories_file.get_absolute_path(), "r+") as f:
categories_name: list[str] = f.read()

View File

@ -1,87 +0,0 @@
:root {
--bg1: #002b36;
--bg2: #073642;
--content1: #586e75;
--content2: #657b83;
--content3: #839496;
--content4: #93a1a1;
--lbg1: #eee8d5;
--lbg2: #fdf6e3;
}
body {
background-color: var(--bg1);
display: flex;
flex-direction: column;
align-items: center;
margin: 15% 15%;
margin-top: 5%;
height: auto;
}
.readme {
background-color: var(--bg2);
}
.picture-container {
background-color: var(--bg2);
padding: 10px;
}
.picture {
padding: 5px;
background-color: var(--content1);
}
.albums_container {
margin-right: 0;
}
img {
max-width: 100%;
height: auto;
}
.meta-picture, .navigation {
display: flex;
flex-direction: row;
justify-content: space-between;
width: 100%;
}
.profile {
text-align: right;
}
a {
color: white;
text-decoration: none;
font-size: 1.5rem;
}
@media screen and (max-width:767px) {
body {
margin: 0% 0%;
}
}
.exif, .readme {
width: 100%;
display: block;
}
.download {
width: 100%;
background-color: var(--bg2);
text-align: center;
}
.exif summary {
text-align: center;
}
.exif details {
display: flex;
justify-content: center;
background-color: var(--bg2);
}

View File

@ -1,70 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/bulk/bulk_page.css">
</head>
<body>
<div class="navigation">
{% if page.prev %}
<a href="{{ page.prev.html.get_url() }}">Prev</a>
{% endif %}
{% if page.next %}
<a class="next" href="{{ page.next.html.get_url() }}">Next</a>
{% endif %}
</div>
{% if page.render_readme() %}
<div class="readme">
<details>
<summary>
README
</summary>
<div class="readme-content">
{{page.render_readme()}}
</div>
</details>
</div>
{% endif %}
<div class="picture-container">
{% for picture in page._pictures %}
<div class="picture-container-item" id="{{ picture.id}}">
<div class="picture">
<a href="{{ picture.get_small().get_url() }}">
<img src='{{ picture.get_small().get_url() }}'>
</a>
<div class="meta-picture">
<a href="{{ picture.get_large().get_url() }}">Large</a>
{% if picture._profile_file.exist() %}
<a class="profile" href="{{ picture.get_profile_file().get_url() }}">Raw therapee profile</a>
{% endif %}
</div>
</div>
<div class="categories_container">
<h1>Categories:</h1>
{% for category in picture.categories %}
<a href="{{ category.path.get_url() }}" class="category_item">{{ al }}</a>
{% endfor %}
</div>
</div>
{% endfor %}
</div>
{% if page.get_raw().exist() %}
<div class="download">
<h1>Download</h1>
<a href="{{ page.get_raw().get_url() }}">RAW</a>
</div>
{% endif %}
{% if page.get_exif() %}
<div class="exif">
<details>
<summary>Exif</summary>
<pre>
{{ page.render_exif() }}
</pre>
</details>
</div>
{% endif %}
</body>
</html>

View File

@ -0,0 +1,6 @@
img {
width: 1000px;
height: 1000px;
}

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/page.css">
</head>
<body>
{{ content }}
</body>
</html>

0
src/templates/home.css Normal file
View File

View File

@ -1,7 +1,13 @@
<!DOCTYPE html>
<html>
<body>
<a href="/bulk/"><h1>Site WIP go to BULK</h1></a>
<a href="/bulk/"><h1>See all pictures I take</h1></a>
<ul>
{% for collection in collections %}
<li>
<a href="{{collection.get_url() }}">{{ collection.get_name()}} </a>
</li>
{% endfor %}
</ul>
</body>
</html>

View File

@ -1,6 +1,87 @@
:root {
--bg1: #002b36;
--bg2: #073642;
--content1: #586e75;
--content2: #657b83;
--content3: #839496;
--content4: #93a1a1;
--lbg1: #eee8d5;
--lbg2: #fdf6e3;
}
body {
background-color: var(--bg1);
display: flex;
flex-direction: column;
align-items: center;
margin: 15% 15%;
margin-top: 5%;
height: auto;
}
.readme {
background-color: var(--bg2);
}
.picture-container {
background-color: var(--bg2);
padding: 10px;
}
.picture {
padding: 5px;
background-color: var(--content1);
}
.albums_container {
margin-right: 0;
}
img {
width: 1000px;
height: 1000px;
max-width: 100%;
height: auto;
}
.meta-picture, .navigation {
display: flex;
flex-direction: row;
justify-content: space-between;
width: 100%;
}
.profile {
text-align: right;
}
a {
color: white;
text-decoration: none;
font-size: 1.5rem;
}
@media screen and (max-width:767px) {
body {
margin: 0% 0%;
}
}
.exif, .readme {
width: 100%;
display: block;
}
.download {
width: 100%;
background-color: var(--bg2);
text-align: center;
}
.exif summary {
text-align: center;
}
.exif details {
display: flex;
justify-content: center;
background-color: var(--bg2);
}

View File

@ -2,11 +2,69 @@
<html>
<head>
<link rel="stylesheet" href="/page.css">
<link rel="stylesheet" href="/bulk/bulk_page.css">
</head>
<body>
{{ content }}
<div class="navigation">
{% if page.prev %}
<a href="{{ page.prev.html.get_url() }}">Prev</a>
{% endif %}
{% if page.next %}
<a class="next" href="{{ page.next.html.get_url() }}">Next</a>
{% endif %}
</div>
{% if page.render_readme() %}
<div class="readme">
<details>
<summary>
README
</summary>
<div class="readme-content">
{{page.render_readme()}}
</div>
</details>
</div>
{% endif %}
<div class="picture-container">
{% for picture in page._pictures %}
<div class="picture-container-item" id="{{ picture.id}}">
<div class="picture">
<a href="{{ picture.get_small().get_url() }}">
<img src='{{ picture.get_small().get_url() }}'>
</a>
<div class="meta-picture">
<a href="{{ picture.get_large().get_url() }}">Large</a>
{% if picture._profile_file.exist() %}
<a class="profile" href="{{ picture.get_profile_file().get_url() }}">Raw therapee profile</a>
{% endif %}
</div>
</div>
<div class="categories_container">
<h1>Categories:</h1>
{% for category in picture.categories %}
<a href="{{ category.path.get_url() }}" class="category_item">{{ al }}</a>
{% endfor %}
</div>
</div>
{% endfor %}
</div>
{% if page.get_raw().exist() %}
<div class="download">
<h1>Download</h1>
<a href="{{ page.get_raw().get_url() }}">RAW</a>
</div>
{% endif %}
{% if page.get_exif() %}
<div class="exif">
<details>
<summary>Exif</summary>
<pre>
{{ page.render_exif() }}
</pre>
</details>
</div>
{% endif %}
</body>
</html>