Skip to content

Commit

Permalink
Fix minor album issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lordiii committed Mar 27, 2024
1 parent 4624df7 commit 2de70d4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
17 changes: 9 additions & 8 deletions albums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
43 changes: 26 additions & 17 deletions ifs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion templates/album/album-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h4>
</h4>

<div class="image-gallery">
{% for subsection in section.subsections %}
{% for subsection in section.subsections | reverse %}
{% set subsection_data = get_section(path=subsection) %}

{% if subsection_data.pages | length > 0 %}
Expand Down

0 comments on commit 2de70d4

Please sign in to comment.