home · contact · privacy
Re-write date handling, remove dependency on filesystem lastmod dates.
[redo-blog] / processor / helpers.sh
index 2869a29a3d414db7066c71e17ff1439b0b7c6c92..64d1123ce89e73ad080cd7a9b614d33266325178 100644 (file)
@@ -6,10 +6,32 @@ escape_html() {
 }
 
 read_and_escape_file() {
-  in=`cat "$1"`
+  in=$(cat "$1")
   escape_html "$in"
 }
 
+get_uuid_from_meta_file() {
+  probable_uuid=$(cat "$1" | head -1)
+  if printf "$probable_uuid" | grep -Eq "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"; then
+    printf "$probable_uuid"
+  else
+    echo "Malformed UUID in meta file." >&2
+    exit 1
+  fi
+}
+
+get_creation_date_from_meta_file_seconds() {
+  cat "$1" | sed -n '2p' | cut -d'_' -f1
+}
+
+get_creation_date_from_meta_file_nanoseconds() {
+  cat "$1" | sed -n '2p'
+}
+
+get_lastmod_date_from_meta_file() {
+  cat "$1" | sed -n '4p'
+}
+
 escape_url() {
   out=`python3 -c 'import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1]))' "$1"`
   printf "%s" "$out"