dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit d38bf7429f09cecafcde27bd45ca767d1b8f6c9c
parent b4a2a2c01acc5b62ea3e0d8a7b40190c38bce2e8
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Mon, 13 Jan 2020 16:19:59 +0100

Add script to generate overview page with newest image

Diffstat:
A.local/bin/html_gallery_newest.sh | 110+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 110 insertions(+), 0 deletions(-)

diff --git a/.local/bin/html_gallery_newest.sh b/.local/bin/html_gallery_newest.sh @@ -0,0 +1,110 @@ +#!/bin/sh +set -e + +version=0.1.0 + +show_help() { + echo "usage: ${0##*/} [OPTIONS] DIR ..." + echo "outputs a html page with the newest image file from each DIR." + echo + echo "OPTIONS are one or more of the following:" + echo " -h, --help show this message" + echo " -v, --version show version and license information" + echo " -V, --verbose show verbose information" + echo " -t, --title <value> set page title" + echo " -s, --stylesheet <path> embed custom css stylesheet" + echo " -- do not consider any following args as options" +} + +show_version() { + echo "${0##*/} version $version" + echo "Licensed under the ISC License" + echo "written by Anders Damsgaard, anders@adamsgaard.dk" + echo "https://src.adamsgaard.dk/dotfiles" +} + +die() { + printf '%s\n' "$1" >&2 + exit 1 +} + +generate_html_header() { + printf "<!DOCTYPE html>\n" + printf "<html lang=\"en\">\n" + printf "<meta charset=\"utf-8\">\n" + printf "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n" + if [ -n "$title" ]; then + printf "<title>%s</title>\n" "$title" + fi + if [ -n "$stylesheet" ]; then + printf "<style>\n%s</style>\n" "$(cat "$stylesheet")" + fi + printf "<article>\n" + if [ -n "$title" ]; then + printf " <header>\n" + printf " <h1>%s</h1>\n" "$title" + printf " </header>\n\n" + fi +} + +generate_html_footer() { + printf "</article>\n" + printf "</html>\n" +} + +get_newest_image() { + ls -1t "$1" | head -1 +} + +generate_html() { + local _i, _dir + generate_html_header + for _dir in "$@"; do + _i="$(get_newest_image "$_dir")" + printf " <a href=\"%s.html\"><img src=\"%s/%s\" alt=\"%s\"/>%s</a><br>\n" \ + "$_dir" "$_dir" "$_i" "$_dir" "$_dir" + done + generate_html_footer +} + +verbose=0 +while :; do + case "$1" in + -h|-\?|--help) + show_help + exit 0 + ;; + -v|--version) + show_version + exit 0 + ;; + -V|--verbose) + verbose=1 + ;; + -t|--title) + title="$2" + shift + ;; + -s|--stylesheet) + stylesheet="$2" + shift + ;; + --) # end all options + shift + break + ;; + -?*) + die 'Error: Unknown option specified' + ;; + *) # No more options + break + esac + shift +done + +if [ $# -lt 1 ]; then + show_help() + exit 1 +fi + +generate_html "$@"