diff --git a/albums.py b/albums.py index 9fd6214..51127be 100644 --- a/albums.py +++ b/albums.py @@ -3,6 +3,7 @@ import os import requests import tempfile +import hashlib from os.path import join as join_path from slugify import slugify from datetime import datetime @@ -36,22 +37,22 @@ def get_url_metadata(path_components: list[str]) -> dict: def get_cover_image(path_components: list[str], tmp_folder_covers: str, image_filename: str) -> str: url = albums_url + "/" + join_web_path(path_components) + "/" + image_filename - joined_components = join_folder_path(path_components) - img_folder_path = join_path(tmp_folder_covers, joined_components) - img_file_path = join_path(img_folder_path, image_filename) + img_data = requests.get(url).content + + filename, file_extension = os.path.splitext(image_filename) + file_hash = hashlib.sha256(img_data).hexdigest() + filename = slugify(filename) + "_" + file_hash + file_extension - if not os.path.exists(img_folder_path): - os.makedirs(img_folder_path) + img_file_path = join_path(tmp_folder_covers, filename) if os.path.exists(img_file_path) and os.path.isfile(img_file_path): - return join_path(joined_components, image_filename) + return filename - img_data = requests.get(url).content img_file = open(img_file_path, "wb") img_file.write(img_data) img_file.close() - return join_path(joined_components, image_filename) + return filename def create_index_md(path_components: list[str], tmp_folder_albums: str, tmp_folder_covers: str, metadata: dict, diff --git a/ifs.py b/ifs.py index c1618a9..6865154 100644 --- a/ifs.py +++ b/ifs.py @@ -18,6 +18,8 @@ date = None ifs_year_folder = None +last_year = "" +year_count = 0 for image in ifs_images: # check if time exists and is after IFS introduction year (2012) @@ -32,28 +34,35 @@ year = date.strftime("%Y") + if last_year != year: + last_year = year + year_count = 0 + ifs_year_folder = ifs_folder + "/" + year if not os.path.exists(ifs_year_folder): os.mkdir(ifs_year_folder) - frontmatter = '+++\n' - frontmatter += 'title = "Images From Space ' + year + '"\n' - frontmatter += 'sort_by = "weight"\n' - frontmatter += 'template = "album/album-list.html"\n' - frontmatter += 'weight = ' + year + '\n' - frontmatter += 'in_search_index = false\n' - frontmatter += '[extra]\n' - frontmatter += 'display_name = ' + year + '\n' - frontmatter += '+++\n' - - f = open(ifs_year_folder + "/_index.md", "w") - f.write(frontmatter) - f.close() - - f = open(ifs_year_folder + "/_index.en.md", "w") - f.write(frontmatter) - f.close() + year_count += 1 + + frontmatter = '+++\n' + frontmatter += 'title = "Images From Space ' + year + '"\n' + frontmatter += 'sort_by = "weight"\n' + frontmatter += 'template = "album/album-list.html"\n' + frontmatter += 'weight = ' + year + '\n' + frontmatter += 'in_search_index = false\n' + frontmatter += '[extra]\n' + frontmatter += 'display_name = ' + year + '\n' + frontmatter += 'image_count = ' + str(year_count) + '\n' + frontmatter += '+++\n' + + f = open(ifs_year_folder + "/_index.md", "w") + f.write(frontmatter) + f.close() + + f = open(ifs_year_folder + "/_index.en.md", "w") + f.write(frontmatter) + f.close() image_id = int(image["filename"].split(".")[0]) image_id_str = str(image_id) diff --git a/templates/album/album-list.html b/templates/album/album-list.html index 2f1534a..29f6535 100644 --- a/templates/album/album-list.html +++ b/templates/album/album-list.html @@ -7,7 +7,7 @@