i hate html

This commit is contained in:
2024-06-26 15:50:09 +02:00
committed by Flo Greistorfer
parent 1f7dad2a87
commit 86d23defae

View File

@@ -11,6 +11,21 @@ webroot = "https://pictures.sorogon.eu/"
imgext = [".jpg", ".jpeg", ".JPG", ".JPEG"]
rawext = [".ARW", ".tif", ".tiff", ".TIF", ".TIFF"]
htmlheader = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pictures</title>
<style>
img {
width: 100px;
}</style>
</head>
<body>
"""
def listfolder(folder: str):
items: list[str] = os.listdir(folder)
@@ -22,14 +37,15 @@ def listfolder(folder: str):
os.mkdir(os.path.join(root, ".previews", folder.removeprefix(root)))
with open(os.path.join(folder, "list.txt"), "w", encoding="utf-8") as f:
f.write(htmlheader)
for item in items:
if item != "Galleries" and item != ".previews":
if os.path.isdir(os.path.join(folder, item)):
subfolders.extend([f'<b><a href="{webroot}{folder.removeprefix(root)}/{item}">{item}</a></b><br>'])
subfolders.extend([f'<a href="{webroot}{folder.removeprefix(root)}/{item}">{item}</a><br>'])
listfolder(os.path.join(folder, item))
else:
if os.path.splitext(item)[1] in imgext:
images.extend([f'<img href="{webroot}{folder.removeprefix(root)}/{item}">{item}</img><br>'])
images.extend([f'<a href="{webroot}{folder.removeprefix(root)}/{item}"><img src="{webroot}{folder.removeprefix(root)}/{item}" alt="{item}"/></a><br>'])
if not os.path.exists(os.path.join(root, ".previews", folder.removeprefix(root), item)):
# os.system(f'magick {os.path.join(folder, item)} -resize 1024x768! {os.path.join(root, ".previews", folder.removeprefix(root), item)}')
print(f'magick {os.path.join(folder, item)} -resize 1024x768! {os.path.join(root, ".previews", folder.removeprefix(root), item)}')
@@ -42,6 +58,7 @@ def listfolder(folder: str):
for subfolder in subfolders:
f.write(subfolder)
f.write("\n")
f.write("</body></html>")
f.close()
@@ -52,6 +69,8 @@ def main():
root += "/"
if not webroot.endswith("/"):
webroot += "/"
if not os.path.exists(os.path.join(root, ".previews")):
os.mkdir(os.path.join(root, ".previews"))
listfolder(root)
# @TODO: write actual html files (and css 🙄)