Skip to content

Commit

Permalink
IFS pagination by year
Browse files Browse the repository at this point in the history
  • Loading branch information
lordiii committed Mar 21, 2024
1 parent 6029c6d commit 7634ed8
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 24 deletions.
5 changes: 2 additions & 3 deletions content/images/ifs/_index.en.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
+++
title = "Images From Space"
weight = 10
sort_by = "weight"
redirect_to = "/en/images/ifs/all/"
template = "ifs/ifs-year.html"
description = "List of all Images From Space grouped by year"
+++

5 changes: 2 additions & 3 deletions content/images/ifs/_index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
+++
title = "Images From Space"
weight = 10
sort_by = "weight"
redirect_to = "/images/ifs/all/"
template = "ifs/ifs-year.html"
description = "Liste aller Images From Space nach Jahr gruppiert"
+++
4 changes: 2 additions & 2 deletions content/images/ifs/all/_index.en.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
+++
title = "All Images From Space"
sort_by = "weight"
weight = 10
template = "ifs/ifs-all.html"
paginate_by = 50
paginate_by = 100
description = "List of all Images From Space"
+++
4 changes: 2 additions & 2 deletions content/images/ifs/all/_index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
+++
title = "All Images From Space"
sort_by = "weight"
weight = 10
template = "ifs/ifs-all.html"
paginate_by = 50
paginate_by = 100
description = "Liste aller Images From Space"
+++
50 changes: 46 additions & 4 deletions ifs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import os, errno, json, requests
from datetime import datetime

ifs_folder = os.environ["IFS_FOLDER"]
ifs_path = os.environ["IFS_PATH"]
Expand All @@ -10,19 +11,60 @@
ifs_folder_all = ifs_folder + "/all"

ifs_data = json.loads(requests.get(ifs_meta_path).text)
ifs_images = ifs_data["images"]

ifs_images = ifs_data["images"][::-1]
ifs_count = len(ifs_images)

total = 0

date = None
ifs_year_folder = None

for image in ifs_images:
# check if time exists and is after IFS introduction year (2012)
if image["exif"]["time"] and image["exif"]["time"] > 1325416332000:
date = datetime.utcfromtimestamp(int(image["exif"]["time"]) / 1000)

date_str = date.strftime("%Y-%m-%d")
datetime_str = date_str + "T" + date.strftime("%H:%M:%S")

year = date.strftime("%Y")

ifs_year_folder = ifs_folder_all + "/" + 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 = "ifs/ifs-all.html"\n'
frontmatter += 'paginate_by = 100\n'
frontmatter += 'weight = ' + year + '\n'
frontmatter += 'transparent = true\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)
title = 'IFS ' + image_id_str

frontmatter = '+++\n'
frontmatter += 'title = "' + title + '"\n'
frontmatter += 'slug = "' + image_id_str + '"\n'
frontmatter += 'weight = ' + str(ifs_count - image_id) + '\n'
frontmatter += 'template = "ifs/ifs-single.html"\n'

if image["exif"]["time"]:
frontmatter += 'date = "' + datetime_str + '"\n'

frontmatter += '[extra]\n'
frontmatter += 'image_filename = "' + image["filename"] + '"'
frontmatter += "\nwidth = " + str(image["width"])
Expand All @@ -41,19 +83,19 @@
content += '[' + image_elem + '](' + ifs_image_path + '/' + image["filename"] + ')\n'
content += '{{ button(text=">>", location="/images/ifs/all/' + str(image_id - 1) + '", disabled="' + str(image_id - 1 <= 0) + '") }}\n'

f = open(ifs_folder_all + "/" + image_id_str + ".md", "w")
f = open(ifs_folder_all + "/" + year + "/" + "IFS-" + image_id_str + ".md", "w")
f.write(frontmatter)
f.write(content.replace("%replace_with_text%", "Alle Images From Space"))
f.close()

f = open(ifs_folder_all + "/" + image_id_str + ".en.md", "w")
f = open(ifs_folder_all + "/" + year + "/" + "IFS-" + image_id_str + ".en.md", "w")
f.write(frontmatter)
f.write(content.replace("%replace_with_text%", "All Images From Space"))
f.close()

total += 1

print("IFS markdown page for " + image_id_str + " created")
print("IFS markdown page for IFS " + image_id_str + " created")


print("Created a total of " + str(total) + " IFS markdown pages")
7 changes: 0 additions & 7 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@
</p>
</div>
</footer>

{% if config.mode == "serve" %}
<pre class="d-none">
{{ __tera_context }}
</pre>
{% endif %}

</div>

<script src="/js/site.js"></script>
Expand Down
25 changes: 23 additions & 2 deletions templates/ifs/ifs-all.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,34 @@

{% block extra_meta %}
<meta property="og:type" content="article" />

{{
macros::sd_article(
title=section.title,
image_url=config.extra.resource_base ~ "/media/img/mainframe-logo.svg",
created="2012-01-01T23:42",
updated=paginator.pages[0].date,
author=config.author,
description=section.description | default(value="")
)
}}

{{
macros::og_article(
author=config.author,
section="Images From Space",
created="2012-01-01T23:42",
updated=paginator.pages[0].date)
}}

{% for page in paginator.pages %}
{% set page_data = get_page(path=page.relative_path) %}

{{
self::sd_image(
image_url=config.extra.ifs_base_path ~ "/" ~ page_data.extra.image_filename,
author=config.author,
title="IFS"
title=page_data.title
)
}}

Expand All @@ -20,11 +40,12 @@
{% block main %}

{% set base_path = paginator.base_url %}

{% include "ifs/ifs-pagination.html" %}

<div class="image-gallery">
{% for page in paginator.pages %}

{% set page_data = get_page(path=page.relative_path) %}
{% set scaling = 200 / page_data.extra.height %}
{% set height = 200 %}
Expand Down
4 changes: 3 additions & 1 deletion templates/ifs/ifs-pagination.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% if paginator.number_pagers > 1 %}
<ul class="pagination pagination-sm justify-content-center my-2 mx-auto">
<li class="page-item">
<a class="text-center page-link {% if not paginator.previous %}disabled{% endif %}" href="{{ paginator.previous }}" style="width: 3em;">
Expand Down Expand Up @@ -51,4 +52,5 @@
>>
</a>
</li>
</ul>
</ul>
{% endif %}
60 changes: 60 additions & 0 deletions templates/ifs/ifs-year.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{% extends "base.html" %}
{% import "macros.html" as macros %}


{% block extra_meta %}
<meta property="og:type" content="article" />

{% set all_section = get_section(path="images/ifs/all/_index.md") %}

{% set latest_page = all_section.pages | first %}
{% set latest_page_data = get_page(path=latest_page.relative_path) %}

{{
macros::sd_article(
title=section.title,
image_url=config.extra.resource_base ~ "/media/img/mainframe-logo.svg",
created="2012-01-01T23:42",
updated=latest_page_data.date,
author=config.author,
description=section.description
)
}}

{{
macros::og_article(
author=config.author,
section="Images From Space",
created="2012-01-01T23:42",
updated=latest_page_data.date
)
}}

{% endblock extra_meta %}

{% block content %}
{% set all_section = get_section(path="images/ifs/all/_index.md") %}

{% for subsection in all_section.subsections | reverse %}
{% set subsection_data = get_section(path=subsection) %}
{% set latest_page = subsection_data.pages | first %}

<div class="d-flex">
<a class="shadow m-2" href="{{subsection_data.path}}">
<h5>
{{ subsection_data.title }}
</h5>
<img alt="{{ latest_page.title }}"
class="w-100 img-thumbnail"
style="max-height: 250px;"
loading="lazy"
decoding="async"
src="{{ config.extra.ifs_base_path }}/.thumbs/750-{{ latest_page.extra.filename }}"
/>
</a>
</div>


{% endfor %}

{% endblock content %}

0 comments on commit 7634ed8

Please sign in to comment.