mirror of
https://github.com/greflm13/StaticGalleryBuilder.git
synced 2026-02-05 02:59:27 +00:00
going home to fix...
This commit is contained in:
21
builder.py
21
builder.py
@@ -4,7 +4,7 @@ import argparse
|
||||
import urllib.parse
|
||||
import shutil
|
||||
import fnmatch
|
||||
import time
|
||||
import json
|
||||
from multiprocessing import Pool
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
@@ -140,6 +140,9 @@ def get_total_folders(folder: str, _total: int = 0) -> int:
|
||||
|
||||
|
||||
def list_folder(folder: str, title: str) -> None:
|
||||
sizelist: Dict[Dict[str, int], Dict[str, int]] = {}
|
||||
with open(os.path.join(folder, "sizelist.json"), "w+", encoding="utf-8") as sizelistfile:
|
||||
sizelist = json.loads(sizelistfile.read())
|
||||
items = os.listdir(folder)
|
||||
items.sort()
|
||||
images: List[Dict[str, Any]] = []
|
||||
@@ -168,14 +171,19 @@ def list_folder(folder: str, title: str) -> None:
|
||||
extsplit = os.path.splitext(item)
|
||||
contains_files = True
|
||||
if extsplit[1].lower() in args.file_extensions:
|
||||
if not sizelist.get(item):
|
||||
print("fuck")
|
||||
with Image.open(os.path.join(folder, item)) as img:
|
||||
width, height = img.size
|
||||
sizelist[item] = {"width": width, "height": height}
|
||||
print(sizelist)
|
||||
|
||||
image = {
|
||||
"url": f"{args.web_root_url}{baseurl}{urllib.parse.quote(item)}",
|
||||
"thumbnail": f"{args.web_root_url}.thumbnails/{baseurl}{urllib.parse.quote(extsplit[0])}.jpg",
|
||||
"name": item,
|
||||
"width": width,
|
||||
"height": height,
|
||||
"width": sizelist[item]["width"],
|
||||
"height": sizelist[item]["height"],
|
||||
}
|
||||
if not os.path.exists(os.path.join(args.root_directory, ".thumbnails", foldername, item)):
|
||||
thumbnails.append((folder, item))
|
||||
@@ -194,6 +202,7 @@ def list_folder(folder: str, title: str) -> None:
|
||||
if not args.non_interactive_mode:
|
||||
imgpbar.update(1)
|
||||
pbar.update(0)
|
||||
sizelistfile.write(json.dumps(sizelist, indent=4))
|
||||
if not contains_files and not args.use_fancy_folders:
|
||||
return
|
||||
if images or (args.use_fancy_folders and not contains_files) or (args.use_fancy_folders and args.ignore_other_files):
|
||||
@@ -201,7 +210,11 @@ def list_folder(folder: str, title: str) -> None:
|
||||
with open(os.path.join(folder, "index.html"), "w", encoding="utf-8") as f:
|
||||
_info: List[str] = None
|
||||
header = os.path.basename(folder) or title
|
||||
parent = None if not foldername else f"{args.web_root_url}{urllib.parse.quote(foldername.removesuffix(folder.split('/')[-1] + '/'))}"
|
||||
parent = (
|
||||
None
|
||||
if not foldername
|
||||
else f"{args.web_root_url}{urllib.parse.quote(foldername.removesuffix(folder.split('/')[-1] + '/'))}"
|
||||
)
|
||||
license_info: cclicense.License = (
|
||||
{
|
||||
"project": args.site_title,
|
||||
|
||||
BIN
test/example/example copy.jpg
Normal file
BIN
test/example/example copy.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 MiB |
10
test/example/sizelist.json
Normal file
10
test/example/sizelist.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"example copy.jpg": {
|
||||
"width": 7030,
|
||||
"height": 4688
|
||||
},
|
||||
"example.jpg": {
|
||||
"width": 7030,
|
||||
"height": 4688
|
||||
}
|
||||
}
|
||||
0
test/sizelist.json
Normal file
0
test/sizelist.json
Normal file
Reference in New Issue
Block a user