File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed
Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change 77# cp .githooks/pre-commit .git/hooks/pre-commit
88# chmod +x .git/hooks/pre-commit
99
10-
1110# Get the current date in "Month Day, Year" format (e.g., March 23, 2025)
1211CURRENT_DATE=$( date -u +" %B %d, %Y" )
1312
1413# Function to update frontmatter
1514update_frontmatter () {
1615 local file=$1
17- if grep -q " ^updated_at:" " $file " ; then
18- # Update the existing updated_at field (macOS and Linux compatible)
19- sed -i " " -E " s/^updated_at:.*/updated_at: $CURRENT_DATE /" " $file "
20- else
21- # Add updated_at field if it doesn't exist (macOS and Linux compatible)
22- sed -i " " -E " /^---$/a\\
16+
17+ # Ensure the file contains frontmatter
18+ if [[ $( head -n 1 " $file " ) == " ---" ]]; then
19+ if grep -q " ^updated_at:" " $file " ; then
20+ # Update the existing "updated_at" field
21+ sed -i " " -E " s/^updated_at:.*/updated_at: $CURRENT_DATE /" " $file "
22+ else
23+ # Insert "updated_at" on the second line of the file
24+ sed -i " " " 2i\\
2325updated_at: $CURRENT_DATE
2426" " $file "
27+ fi
2528 fi
2629}
2730
@@ -33,3 +36,5 @@ for file in $(git diff --cached --name-only -- '*.mdx'); do
3336 git add " $file "
3437 fi
3538done
39+
40+
You can’t perform that action at this time.
0 commit comments