script waits for enter press before exiting, HTML file exists as example from the start / does not get overwritten by script, blacklisting hidden files from csv table, blacklisting gitkeep and gitignore from git archive generation
parent
6dcbb497ce
commit
4755ec3c1b
|
@ -0,0 +1,2 @@
|
||||||
|
/**/.gitkeep export-ignore
|
||||||
|
/**/.gitignore export-ignore
|
|
@ -1,5 +1,6 @@
|
||||||
gallery/**
|
gallery/**
|
||||||
!gallery/**/
|
!gallery/**/
|
||||||
!gallery/**/.gitkeep
|
!gallery/**/.gitkeep
|
||||||
|
!gallery/index.html
|
||||||
gallery-items*.csv
|
gallery-items*.csv
|
||||||
__pycache__
|
__pycache__
|
||||||
|
|
|
@ -12,6 +12,17 @@ THUMBNAIL_FOLDER = Path(__file__, "..", "gallery", "thumbs").resolve()
|
||||||
THUMBNAIL_SUFFIX = "-thumb.webp"
|
THUMBNAIL_SUFFIX = "-thumb.webp"
|
||||||
THUMBNAIL_MAX_FRAMES = 0 # No limit. Feel free to adjust this if you're hosting long animations on there or something.
|
THUMBNAIL_MAX_FRAMES = 0 # No limit. Feel free to adjust this if you're hosting long animations on there or something.
|
||||||
|
|
||||||
|
FILE_BLACKLIST = [
|
||||||
|
# Dot files (e.g. .gitkeep, .gitignore, .DS_Store) are ignored by default.
|
||||||
|
# Windows does not do us the courtesy of having all hidden files start with a period,
|
||||||
|
# so I'm filtering some of the common ones out "by hand".
|
||||||
|
# It's possible that I'm missing a couple of common ones.
|
||||||
|
# If your gallery-items.csv winds up with entries for any files that you
|
||||||
|
# don't want in your gallery, please feel free to expand this list by hand.
|
||||||
|
"Thumbs.db", # Windows Thumbnail Cache
|
||||||
|
"Desktop.ini" # Windows Folder Settings
|
||||||
|
]
|
||||||
|
|
||||||
def generate_and_register_thumbnail(file_path, thumbnail_path):
|
def generate_and_register_thumbnail(file_path, thumbnail_path):
|
||||||
try:
|
try:
|
||||||
generate_thumbnail(file_path, thumbnail_path)
|
generate_thumbnail(file_path, thumbnail_path)
|
||||||
|
@ -57,6 +68,15 @@ def prompt_confirmation(prompt_message):
|
||||||
def print_horizontal_separator():
|
def print_horizontal_separator():
|
||||||
print("--------------")
|
print("--------------")
|
||||||
|
|
||||||
|
def is_file_blacklisted(file_name):
|
||||||
|
if file_name.startswith("."):
|
||||||
|
return True # Hidden files on Linux and Mac
|
||||||
|
elif file_name in FILE_BLACKLIST:
|
||||||
|
return True # Specifically blacklisted
|
||||||
|
else:
|
||||||
|
return False # Fine
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__": # Only do this when the script is run directly
|
if __name__ == "__main__": # Only do this when the script is run directly
|
||||||
|
|
||||||
print("Generating thumbnails...")
|
print("Generating thumbnails...")
|
||||||
|
@ -72,6 +92,9 @@ if __name__ == "__main__": # Only do this when the script is run directly
|
||||||
# for all images discovered in the folder:
|
# for all images discovered in the folder:
|
||||||
|
|
||||||
for file_name in os.listdir(MEDIA_FOLDER):
|
for file_name in os.listdir(MEDIA_FOLDER):
|
||||||
|
if is_file_blacklisted(file_name):
|
||||||
|
continue
|
||||||
|
|
||||||
print("Checking \"{}\"...".format(file_name))
|
print("Checking \"{}\"...".format(file_name))
|
||||||
file_path = Path(MEDIA_FOLDER, file_name).resolve()
|
file_path = Path(MEDIA_FOLDER, file_name).resolve()
|
||||||
|
|
||||||
|
@ -159,3 +182,4 @@ if __name__ == "__main__": # Only do this when the script is run directly
|
||||||
print("Error writing table:")
|
print("Error writing table:")
|
||||||
print("{error_name}: {error}".format(error_name=type(error).__name__, error=error))
|
print("{error_name}: {error}".format(error_name=type(error).__name__, error=error))
|
||||||
|
|
||||||
|
input("Press Enter key to exit...")
|
||||||
|
|
|
@ -4,7 +4,7 @@ from pathlib import Path
|
||||||
|
|
||||||
from lib import GalleryTable
|
from lib import GalleryTable
|
||||||
|
|
||||||
GALLERY_ID = "gallery" # e.g. <div id="gallery"/>
|
GALLERY_ID = "gallery" # e.g. <div id="gallery"/> will turn into the gallery.
|
||||||
|
|
||||||
GALLERY_CONFIG_PATH = Path(__file__, "..", "nanogallery2-config.json").resolve()
|
GALLERY_CONFIG_PATH = Path(__file__, "..", "nanogallery2-config.json").resolve()
|
||||||
JAVASCRIPT_OUTPUT_PATH = Path(__file__, "..", "gallery", "gallery.js").resolve()
|
JAVASCRIPT_OUTPUT_PATH = Path(__file__, "..", "gallery", "gallery.js").resolve()
|
||||||
|
@ -70,7 +70,7 @@ if __name__ == "__main__": # Only do this when the script is run directly
|
||||||
|
|
||||||
gallery_items = []
|
gallery_items = []
|
||||||
|
|
||||||
print("Creating HTML and JS...")
|
print("Creating gallery javascript file...")
|
||||||
|
|
||||||
for name, entry in table.items():
|
for name, entry in table.items():
|
||||||
gallery_items.append({
|
gallery_items.append({
|
||||||
|
@ -100,39 +100,13 @@ if __name__ == "__main__": # Only do this when the script is run directly
|
||||||
), " ")
|
), " ")
|
||||||
)
|
)
|
||||||
|
|
||||||
output_html = inspect.cleandoc(
|
|
||||||
"""
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<head>
|
|
||||||
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">
|
|
||||||
|
|
||||||
<!-- These are required to load the nanogallery2 code: -->
|
|
||||||
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>
|
|
||||||
<link href="https://cdn.jsdelivr.net/npm/nanogallery2@3/dist/css/nanogallery2.min.css" rel="stylesheet" type="text/css">
|
|
||||||
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/nanogallery2@3/dist/jquery.nanogallery2.min.js"></script>
|
|
||||||
|
|
||||||
<!-- This contains the settings and gallery items for your personal gallery: -->
|
|
||||||
<script type="text/javascript" src="gallery.js"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Gallery</h1>
|
|
||||||
|
|
||||||
<!-- Below is the actual gallery: -->
|
|
||||||
<div id="{gallery_id}"/>
|
|
||||||
</body>
|
|
||||||
"""
|
|
||||||
).format(
|
|
||||||
gallery_id=GALLERY_ID
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(HTML_OUTPUT_PATH, "w", encoding="utf-8") as html_output_file:
|
|
||||||
html_output_file.write(output_html)
|
|
||||||
|
|
||||||
with open(JAVASCRIPT_OUTPUT_PATH, "w", encoding="utf-8") as js_output_file:
|
with open(JAVASCRIPT_OUTPUT_PATH, "w", encoding="utf-8") as js_output_file:
|
||||||
js_output_file.write(output_js)
|
js_output_file.write(output_js)
|
||||||
|
|
||||||
print("All done!")
|
print("All done!")
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print("Could not write HTML and JS files:")
|
print("Could not write the javascript file:")
|
||||||
print(error)
|
print(error)
|
||||||
|
|
||||||
|
input("Press Enter key to exit...")
|
|
@ -0,0 +1,29 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<head>
|
||||||
|
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">
|
||||||
|
|
||||||
|
<!-- These are always required to load the general nanogallery2 code: -->
|
||||||
|
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/nanogallery2@3/dist/css/nanogallery2.min.css" rel="stylesheet" type="text/css">
|
||||||
|
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/nanogallery2@3/dist/jquery.nanogallery2.min.js"></script>
|
||||||
|
|
||||||
|
<!-- This is the gallery.js file generated by the second script.
|
||||||
|
It contains the settings and gallery items for your own personal gallery: -->
|
||||||
|
<script type="text/javascript" src="gallery.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<h1>Gallery</h1>
|
||||||
|
|
||||||
|
<!-- This is the placeholder that gets turned into the actual gallery by the script: -->
|
||||||
|
<div id="gallery"/>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
|
||||||
|
</footer>
|
||||||
|
</body>
|
Loading…
Reference in New Issue