Skip to content

Commit d1e7f58

Browse files
committed
Extract function: date_from_front_matter
1 parent e7a2519 commit d1e7f58

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

bin/check_dates

+11-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ function date_from_filename () {
88
}
99

1010

11+
function date_from_front_matter() {
12+
local file="${1}"
13+
cat "$file" |
14+
perl -n -e '$front_matter .= $_ if /---/.../---/; END { print $1 if $front_matter =~ /date:\s+([0-9-]+)/;}'
15+
}
16+
1117

1218
function main () {
1319
# Directory containing posts
@@ -25,16 +31,16 @@ function main () {
2531
date_from_filename=$( date_from_filename "$filename" )
2632

2733
# Extract date from front matter
28-
frontmatter_date=$( cat "$file" | perl -n -e '$front_matter .= $_ if /---/.../---/; END { print $1 if $front_matter =~ /date:\s+([0-9-]+)/;}')
34+
date_from_front_matter=$( date_from_front_matter "${file}" )
2935

3036
# Compare file date with front matter date
31-
if [[ "$date_from_filename" = '' ]] || [[ "$date_from_filename" != "$frontmatter_date" ]]; then
37+
if [[ "$date_from_filename" = '' ]] || [[ "$date_from_filename" != "$date_from_front_matter" ]]; then
3238
echo "Inconsist or missing date info: $file"
33-
echo " Date From Filename: '$date_from_filename'"
34-
echo " Front matter date: '$frontmatter_date'"
39+
echo " Date From Filename: '$date_from_filename'"
40+
echo " Date From Front Matter: '$date_from_front_matter'"
3541
inconsistent=true
3642
else
37-
# echo "Consistent|$file|$filename|$date_from_filename|$frontmatter_date|"
43+
# echo "Consistent|$file|$filename|$date_from_filename|$date_from_front_matter|"
3844
:
3945
fi
4046
done

0 commit comments

Comments
 (0)