瀏覽代碼

Prepare generation of thumb photos

master
Marien Fressinaud 6 年之前
父節點
當前提交
8ba92e9046
共有 3 個檔案被更改,包括 16 行新增4 行删除
  1. 1
    1
      Herisson/gallery.html.j2
  2. 1
    1
      Herisson/index.html.j2
  3. 14
    2
      boop.py

+ 1
- 1
Herisson/gallery.html.j2 查看文件

@@ -24,7 +24,7 @@
{% for photo in gallery.photos %}
<div class="photo">
<a href="{{ photo.url }}" target="_blank" rel="noreferrer">
<img src="{{ photo.url }}" alt="" />
<img src="{{ photo.thumb_url }}" alt="" />
</a>
</div>
{% endfor %}

+ 1
- 1
Herisson/index.html.j2 查看文件

@@ -22,7 +22,7 @@
{% for gallery in galleries -%}
<div class="gallery-cover">
<a href="{{ gallery.url }}.html">
<img src="{{ gallery.cover_photo.url }}" alt="" />
<img src="{{ gallery.cover_photo.thumb_url }}" alt="" />
<span class="gallery-cover-name">
{{ gallery.name }}
</span>

+ 14
- 2
boop.py 查看文件

@@ -40,7 +40,13 @@ def list_photos_in(gallery_dir):
]
for photo_file in photo_files:
url = os.path.join(gallery_dir.name, photo_file.name)
photo = {"name": photo_file.name, "url": url}
thumb_url = os.path.join(gallery_dir.name, f"thumb_{photo_file.name}")
photo = {
"name": photo_file.name,
"path": photo_file.path,
"url": url,
"thumb_url": thumb_url,
}
yield photo


@@ -97,7 +103,13 @@ def generate_gallery_dir(output_path, gallery):
gallery_output_path = os.path.join(output_path, gallery["name"])
if os.path.isdir(gallery_output_path):
os.mkdir(gallery_output_path)
shutil.copytree(gallery["path"], gallery_output_path)

for photo in gallery["photos"]:
photo_output_path = os.path.join(output_path, photo["url"])
shutil.copyfile(photo["path"], photo_output_path)

thumb_output_path = os.path.join(output_path, photo["thumb_url"])
shutil.copyfile(photo["path"], thumb_output_path)


def main():

Loading…
取消
儲存