#!/bin/bash
name="hugo-extract-timestamp"
version="1.0"
read -r -d '' help_message <<-EOF
Extract a date/timestamp from a Hugo content files
Usage: hugo-extract-timestamp [OPTIONS] [TARGETS ..]
Options:
-h, --help print this message and exit
-q, --quiet suppress error messages
-v, --verbose show additional messages
-V, --version print version number and exit
EOF
source /usr/local/lib/mylib.bash
. /usr/local/lib/myparse.bash
# if no filenames given
if [[ ${#positional[@]} -eq 0 ]]; then
usage_msg
fi
code=0
newdate="$(hugo-date)"
for filename in "${positional[@]}"; do
# if filename does not exist
if [[ ! -f "$filename" ]]; then
nonfatal_error_msg "No such file '$filename'"
code=1
# if filename does not contain timestamp
elif ! /usr/bin/grep --quiet "$filename" --regexp="^date:"; then
if [[ "$verbose" -eq 1 ]]; then
debug_error_msg "No timestamp in '$filename'"
fi
/usr/bin/echo
code=1
# main routine
else
/usr/bin/grep "$filename" --regexp="^date:" | /usr/bin/sed --expression="s/^date: *//"
fi
done
# exit with accumulated error code
exit "$code"