Skip to content

Commit da5430b

Browse files
committed
New script: bin/check_dates
1 parent 0e81376 commit da5430b

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

.github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ jobs:
5151
mkdir -p _site/blog
5252
bundle exec jekyll build --source . --destination _site --config _config.yml --drafts
5353
54+
- name: List files for debugging
55+
run: ls -la . bin/ _site/ _drafts/
56+
5457
- name: Set permissions on _site
5558
run: chmod -R a-w _site
5659

bin/check_dates

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# Directory containing posts
4+
POSTS_DIR="_posts"
5+
6+
# Flag to track if any inconsistencies are found
7+
inconsistent=false
8+
9+
# Iterate over each post file in the _posts directory
10+
for file in "$POSTS_DIR"/*.md; do
11+
# Extract filename without extension
12+
filename=$(basename "$file" .md)
13+
14+
# Extract date from filename (assumes format YYYY-MM-DD-title)
15+
file_date=$(echo "$filename" | cut -d'-' -f1-3 | sed 's/-//g')
16+
17+
# Extract date from front matter
18+
frontmatter_date=$(sed -n 's/^date: \(.*\)/\1/p' "$file" | cut -d'T' -f1)
19+
20+
# Compare file date with front matter date
21+
if [ "$file_date" != "$frontmatter_date" ]; then
22+
echo "Inconsistency found in $file:"
23+
echo " Filename date: $file_date"
24+
echo " Front matter date: $frontmatter_date"
25+
inconsistent=true
26+
fi
27+
done
28+
29+
# Exit with error if inconsistencies were found
30+
if $inconsistent; then
31+
echo "Inconsistencies detected. Please correct them."
32+
exit 1
33+
else
34+
echo "All dates are consistent."
35+
fi

0 commit comments

Comments
 (0)