Skip to content

Commit

Permalink
Count files and inconsistencies, then report at end. Set 'nullglob'
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelRWolf committed Aug 18, 2024
1 parent 988a749 commit da3702f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
4 changes: 1 addition & 3 deletions _drafts/empty_draft.md
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# Heading 1

This file is (mostly) empty.
g
53 changes: 31 additions & 22 deletions bin/check_dates
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,39 @@ function date_from_front_matter() {
function main () {
POSTS_DIR="_posts"
inconsistent=false

for file in "${POSTS_DIR}"/*.md; do
filename=$(basename "$file" .md)

date_from_filename=$( date_from_filename "$filename" )
date_from_front_matter=$( date_from_front_matter "${file}" )

if [[ "${date_from_filename}" = '' ]] || [[ "${date_from_filename}" != "${date_from_front_matter}" ]]; then
warn "Inconsist or missing date info: ${file}"
warn " Date From Filename: '${date_from_filename}'"
warn " Date From Front Matter: '${date_from_front_matter}'"
inconsistent=true
else
# warn "Consistent|${file}|${filename}|${date_from_filename}|${date_from_front_matter}|"
:
fi
done

# Exit with error if inconsistencies were found
if $inconsistent; then
warn "Inconsistencies detected. Please correct them."


export file_count=0
export inconsistent_count=0
{
shopt -s nullglob;
for file in "${POSTS_DIR}"/*.md ; do
((file_count = file_count + 1))

filename=$(basename "$file" .md)

date_from_filename=$( date_from_filename "$filename" )
date_from_front_matter=$( date_from_front_matter "${file}" )

if [[ "${date_from_filename}" = '' ]] ||
[[ "${date_from_filename}" != "${date_from_front_matter}" ]]
then
warn "Inconsist or missing date info: ${file}"
warn " Date From Filename: '${date_from_filename}'"
warn " Date From Front Matter: '${date_from_front_matter}'"
((inconsistent_count=inconsistent_count + 1))
else
# warn "Consistent|${file}|${filename}|${date_from_filename}|${date_from_front_matter}|"
:
fi
done
}

if (($inconsistent_count > 0)); then
warn "Inconsistencies detected in $inconsistent_count file."
exit 1
else
warn "All dates are consistent."
warn "All dates are consistent in $file_count files."
fi
}

Expand Down

0 comments on commit da3702f

Please sign in to comment.