@@ 14,6 14,7 @@ install:
$(call subdir_make,archives,install)
$(call subdir_make,containers,install)
$(call subdir_make,display,install)
+ $(call subdir_make,documents,install)
$(call subdir_make,emulation,install)
$(call subdir_make,games,install)
$(call subdir_make,network,install)
@@ 24,6 25,7 @@ uninstall:
$(call subdir_make,archives,uninstall)
$(call subdir_make,containers,uninstall)
$(call subdir_make,display,uninstall)
+ $(call subdir_make,documents,uninstall)
$(call subdir_make,emulation,uninstall)
$(call subdir_make,games,uninstall)
$(call subdir_make,network,uninstall)
@@ 34,6 36,7 @@ test: clean
$(call subdir_make,archives,test)
$(call subdir_make,containers,test)
$(call subdir_make,display,test)
+ $(call subdir_make,documents,test)
$(call subdir_make,emulation,test)
$(call subdir_make,games,test)
$(call subdir_make,network,test)
@@ 44,6 47,7 @@ clean:
$(call subdir_make,archives,clean)
$(call subdir_make,containers,clean)
$(call subdir_make,display,clean)
+ $(call subdir_make,documents,clean)
$(call subdir_make,emulation,clean)
$(call subdir_make,games,clean)
$(call subdir_make,network,clean)
@@ 0,0 1,48 @@
#!/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"
@@ 0,0 1,75 @@
+#!/bin/bash
+
+name="hugo-timestamp"
+version="1.0"
+read -r -d '' help_message <<-EOF
+ Set a date/timestamp into a Hugo content files
+ Usage: hugo-timestamp [OPTIONS] TARGET DATETIME
+ 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
+
+# error if no filenames given
+if [[ ${#positional[@]} -lt 2 ]]; then
+ usage_msg
+fi
+
+_ed_append_date() {
+ ed -s "$1" <<EOF
+/^title:
+a
+date: "$2"
+.
+w
+q
+EOF
+}
+
+_ed_overwrite_date() {
+ ed -s "$1" <<EOF
+g/^date:/c
+i
+date: "$2"
+.
+w
+q
+EOF
+}
+
+filename="${positional[0]}"
+newdate="${positional[1]}"
+
+# if filename does not exist
+if [[ ! -f "$filename" ]]; then
+ error_msg "No such file '$filename'"
+
+# main routine
+else
+
+ # try read timestamp from file
+ olddate="$(hugo-extract-timestamp "$filename")"
+
+ # branch 1: has no timestamp so append one
+ if [[ -z "$olddate" ]]; then
+ if [[ "$verbose" -eq 1 ]]; then
+ debug_msg "No date found, creating one"
+ fi
+
+ _ed_append_date "$filename" "$newdate"
+
+ # branch 2: has a timestamp so replace it
+ else
+ if [[ "$verbose" -eq 1 ]]; then
+ debug_msg "replacing ${olddate}"
+ fi
+
+ _ed_overwrite_date "$filename" "$newdate"
+ fi
+fi
+