aboutsummaryrefslogtreecommitdiffstats
path: root/templates/gallery.html
blob: 70f5d25b0711beb75113222dca1b6b8445ee10ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!doctype html>
<html>
    <head>
        <title>{{ title }}</title>
        <link
            rel="stylesheet"
            href="{{ url_for('static', filename='style.css') }}"
        />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
    </head>
    <body>
        <script>
            function layout() {
                const isMobile =
                    window.matchMedia("(max-width: 600px)").matches;

                document.querySelectorAll(".gallery-item").forEach((item) => {
                    const img = item.querySelector("img");
                    if (!img) return;

                    if (isMobile) {
                        // On mobile, reset any previously set width
                        item.style.width = "";
                        return;
                    }

                    const setWidth = () => {
                        item.style.width = img.offsetWidth + "px";
                    };

                    if (img.complete) {
                        setWidth();
                    } else {
                        img.addEventListener("load", setWidth, { once: true });
                    }
                });
            }

            document.addEventListener("DOMContentLoaded", layout);
            window.addEventListener("resize", layout);
        </script>

        <h1>
            {{ title }} {% if ig_link %}
            <a href="{{ ig_link }}" target="_blank" class="ig-link">
                <img
                    src="{{ url_for('static', filename='ig.svg') }}"
                    alt="Instagram"
                    width="30"
                    height="30"
                />
            </a>
            {% endif %}
        </h1>

        <!-- -->
        {% for date in dates %}
        <h2>{{ date }}</h2>
        <div class="gallery">
            {% for f in grouped[date] %}
            <div class="gallery-item">
                <a
                    href="https://drive.google.com/file/d/{{ f.id }}/view"
                    target="_blank"
                >
                    <img
                        src="{{ url_for('serve_thumbnail', filename=f.thumbnail.split('/')[-1]) }}"
                        alt="{{ f.name }}"
                        loading="lazy"
                    />
                </a>
                {% if f.description %}
                <p>{{ f.description }}</p>
                {% endif %}
            </div>
            {% endfor %}
        </div>
        {% endfor %} {% if dates|length == 0 %}
        <p>No photos yet.</p>
        {% endif %}
    </body>
</html>