2024-05-12 16:41:55 +00:00
|
|
|
#!/bin/bash
|
2024-05-12 19:41:41 +00:00
|
|
|
[ "$DEBUG" == 'true' ] && set -x
|
|
|
|
[ "$STRICT" == 'true' ] && set -e
|
2024-05-12 16:41:55 +00:00
|
|
|
|
2024-05-12 17:11:39 +00:00
|
|
|
file_path="$1"
|
2024-05-12 19:46:23 +00:00
|
|
|
base_cmd="go-yq --front-matter=process"
|
2024-05-12 16:41:55 +00:00
|
|
|
# Check if the file has valid front matter
|
|
|
|
|
|
|
|
is_empty() {
|
|
|
|
if $(echo "$1" | grep -q "^null$"); then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
is_true() {
|
|
|
|
if $(echo "$1" | grep -q "^true$"); then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "Checking front matter"
|
2024-05-12 22:29:53 +00:00
|
|
|
if ! head -n 1 "$file_path" | grep -q "^---$"; then
|
2024-05-12 16:41:55 +00:00
|
|
|
echo "Front matter (start) not found, adding it"
|
2024-05-12 21:00:07 +00:00
|
|
|
# Dont trace content, as its usually too large
|
2024-05-12 21:33:32 +00:00
|
|
|
[ "$DEBUG" == "true" ] && set +x
|
2024-05-12 22:07:37 +00:00
|
|
|
(echo -e "---\n---\n"; cat "$file_path") >"$file_path.tmp" && mv "$file_path.tmp" "$file_path"
|
2024-05-12 21:33:32 +00:00
|
|
|
[ "$DEBUG" == "true" ] && set -x
|
2024-05-12 16:41:55 +00:00
|
|
|
fi
|
|
|
|
|
2024-05-12 22:52:08 +00:00
|
|
|
wc -l $file_path
|
2024-05-12 22:29:53 +00:00
|
|
|
cat $file_path
|
|
|
|
|
2024-05-12 16:41:55 +00:00
|
|
|
# Get the title from the front matter
|
|
|
|
echo "Checking title"
|
|
|
|
title=$($base_cmd '.title' "$file_path")
|
|
|
|
# Check if the title is empty
|
|
|
|
if is_empty "$title"; then
|
2024-05-12 18:24:36 +00:00
|
|
|
$base_cmd -i '.title="Changelog"' "$file_path"
|
2024-05-12 16:41:55 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Checking pagefind"
|
|
|
|
pagefind=$($base_cmd '.pagefind' "$file_path")
|
|
|
|
if is_empty "$pagefind" || is_true "$pagefind"; then
|
2024-05-12 18:24:36 +00:00
|
|
|
$base_cmd -i '.pagefind=false' "$file_path"
|
2024-05-12 16:41:55 +00:00
|
|
|
fi
|