summaryrefslogtreecommitdiff
path: root/src/lib/album.source.sh
blob: e4b5e9dc451ebc23d23365b6f84dd45a6e7629b1 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Album coordinator: ties together the image pipeline (image-pipeline.source.sh),
# page rendering and parallel orchestration (album-render.source.sh) and the EXIF
# caching / metadata / dry-run plumbing (album-metadata.source.sh) into the
# high-level generate / refresh-splash / dry-run flows the CLI actions call. All
# library modules are sourced before anything runs, so the helpers used here are
# defined regardless of file order.

copy_site_favicon() {
    local asset_dir
    local favicon_src

    # Use the configured favicon when set, otherwise the bundled default. Either
    # way it is published as favicon.ico (the name the templates link to).
    if [ -n "${FAVICON:-}" ]; then
        favicon_src="$FAVICON"
    else
        asset_dir=$(resolve_default_asset_dir)
        favicon_src="$asset_dir/favicon.ico"
    fi

    if [ ! -r "$favicon_src" ]; then
        config_error "favicon file $favicon_src must be readable"
        return 1
    fi

    log_verbose "Copying favicon to $(_display_path "$DIST_DIR/favicon.ico")"
    cp "$favicon_src" "$DIST_DIR/favicon.ico"
}

prepare_generation_site_assets() {
    copy_site_favicon
}

clear_rendered_html() {
    find "$DIST_DIR" -type f -name '*.html' -delete
}

create_generation_archive() {
    local -r tarball_name="$1"; shift

    if [ "$TARBALL_INCLUDE" = yes ]; then
        tarball "$tarball_name"
    fi
}

# Aggregate EXIF stats and render the stats page plus the per-camera pages into
# the dist root (html_dir and backhref are '.', matching render_album_pages).
# Run after the album pages so the per-photo identify cache is already warm.
generate_stats_pages() {
    log_verbose 'Stats page enabled; collecting EXIF stats'
    collect_photo_exif_stats
    # Keep the album root uncluttered: the stats overview is stats/index.html and
    # every filter mini-album lives under stats/<pagebase>/ (see render_filter_pages).
    render_stats_page stats .. index
    render_filter_pages
}

generate() {
    local tarball_name=''

    if [ "$TARBALL_INCLUDE" = yes ]; then
        tarball_name=$(generated_tarball_name)
        log_verbose \
            "Tarball enabled; planned archive:" \
            "$(_display_path "$DIST_DIR/$tarball_name")"
    else
        log_verbose 'Tarball disabled; no archive will be created'
    fi

    if [ "$SHURIKEN_FORCE_GENERATE" = yes ]; then
        clear_exif_cache
    fi
    prepare_generation_photo_assets
    prepare_generation_site_assets
    clear_rendered_html
    render_album_pages 'photos' '.' 'thumbs' 'blurs' '.' "$tarball_name"
    if [ "$STATS_PAGE" = yes ]; then
        generate_stats_pages
    fi
    create_generation_archive "$tarball_name"
    write_generation_metadata "$tarball_name"
}

refresh_splash() {
    local restore_errexit=no
    local -i status=0
    local tmp_html
    local tmp_path

    tmp_path=$(mktemp "$DIST_DIR/.index.html.XXXXXX")
    tmp_html=$(basename "$tmp_path")

    if [[ "$-" == *e* ]]; then
        restore_errexit=yes
        set +e
    fi
    (
        set -e
        render_album_splash_page 'photos' '.' 'blurs' '.' "$tmp_html"
    )
    status=$?
    if [ "$restore_errexit" = yes ]; then
        set -e
    fi
    if (( status != 0 )); then
        rm -f "$DIST_DIR/$tmp_html"
        return "$status"
    fi

    restore_errexit=no
    if [[ "$-" == *e* ]]; then
        restore_errexit=yes
        set +e
    fi
    (
        set -e
        prepare_generation_site_assets
    )
    status=$?
    if [ "$restore_errexit" = yes ]; then
        set -e
    fi
    if (( status != 0 )); then
        rm -f "$DIST_DIR/$tmp_html"
        return "$status"
    fi

    mv "$DIST_DIR/$tmp_html" "$DIST_DIR/index.html"
    log_info "Refreshed splash page $(_display_path "$DIST_DIR/index.html")"
}