#!/bin/sh
# Extract hero images from all .*.html source files in the current directory.
# Lists unique hero files (LIMG) from under img/.
#
# Usage:
#     $0 [-LIMG|-SQTN]
#
# Extract headers for SQTN, or (default) LIMG.

TYPE=LIMG

case $1 in
    -LIMG) TYPE=LIMG;;
    -SQTN) TYPE=SQTN;;
    "") TYPE=LIMG;;
    *) echo ERROR: unknown type 1>&2; exit 1;;
esac

# Can be used to drive eager image rebuilds independent of page rebuilds.
# This could be done by calling with each image:
#     script/get_hero_img_inline insTop ${HEROIMG} .bogus.html ${STATICCDNPREFIX} $MOBILE
#
# It should be sufficient to call this for $MOBILE = false (ie desktop) as:
#   * The mobile/lite site may not uses hero images.
#   * The desktop hero image build may recursively build the 'mobile' header
#     as part of responsive design for smaller screens.
#
# Getting the STATICCDNPREFIX correct may be important to avoid
# creating and cacheing bad HTML.
# A "./" may be sufficient for desktop builds in practice, so:
#     script/get_hero_img_inline insTop ${HEROIMG} .bogus.html "./" false

# May collect too many, since:
#   * This may pick up too many input files including stale ones.
#   * This may pick up bogus values from the body, ie after the header stops.
cat .*.html | \
    awk '/^ *<!--  *'$TYPE'  *img\/[^ ]*  *--> *$/ {
    print $3
    }' | \
    sort -u
