Skip to content

Commit 8a6ef24

Browse files
committed
Clean up messy shell syntax
1 parent d1e7f58 commit 8a6ef24

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

bin/check_dates

+8-17
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,28 @@ function date_from_filename () {
1010

1111
function date_from_front_matter() {
1212
local file="${1}"
13-
cat "$file" |
13+
cat "${file}" |
1414
perl -n -e '$front_matter .= $_ if /---/.../---/; END { print $1 if $front_matter =~ /date:\s+([0-9-]+)/;}'
1515
}
1616

1717

1818
function main () {
19-
# Directory containing posts
2019
POSTS_DIR="_posts"
21-
22-
# Flag to track if any inconsistencies are found
2320
inconsistent=false
2421

25-
# Iterate over each post file in the _posts directory
26-
for file in "$POSTS_DIR"/*.md; do
27-
# Extract filename without extension
22+
for file in "${POSTS_DIR}"/*.md; do
2823
filename=$(basename "$file" .md)
2924

30-
# Extract date from filename (assumes format YYYY-MM-DD-title)
3125
date_from_filename=$( date_from_filename "$filename" )
32-
33-
# Extract date from front matter
3426
date_from_front_matter=$( date_from_front_matter "${file}" )
3527

36-
# Compare file date with front matter date
37-
if [[ "$date_from_filename" = '' ]] || [[ "$date_from_filename" != "$date_from_front_matter" ]]; then
38-
echo "Inconsist or missing date info: $file"
39-
echo " Date From Filename: '$date_from_filename'"
40-
echo " Date From Front Matter: '$date_from_front_matter'"
28+
if [[ "${date_from_filename}" = '' ]] || [[ "${date_from_filename}" != "${date_from_front_matter}" ]]; then
29+
echo "Inconsist or missing date info: ${file}"
30+
echo " Date From Filename: '${date_from_filename}'"
31+
echo " Date From Front Matter: '${date_from_front_matter}'"
4132
inconsistent=true
4233
else
43-
# echo "Consistent|$file|$filename|$date_from_filename|$date_from_front_matter|"
34+
# echo "Consistent|${file}|${filename}|${date_from_filename}|${date_from_front_matter}|"
4435
:
4536
fi
4637
done
@@ -54,4 +45,4 @@ function main () {
5445
fi
5546
}
5647

57-
main "$@"
48+
main "${@}"

0 commit comments

Comments
 (0)