File tree Expand file tree Collapse file tree 1 file changed +7
-9
lines changed
Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -52,15 +52,13 @@ jobs:
5252 sed -i "s/^last-updated:.*$/last-updated: $CURRENT_DATE/" "$file"
5353 else
5454 echo "Adding last-updated field to existing frontmatter"
55- # Add last-updated after the opening ---
56- sed -i "0,/^---$/!{0,/^---$/b;s/^---$/last-updated: $CURRENT_DATE\n---/}" "$file"
57- # If the above didn't work (complex sed), try awk
58- if ! grep -q "^last-updated:" "$file"; then
59- awk -v date="$CURRENT_DATE" '
60- NR==1 && /^---$/ { print; getline; print "last-updated: " date; print; next }
61- { print }
62- ' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
63- fi
55+ # Add last-updated before the closing --- (bottom of frontmatter)
56+ awk -v date="$CURRENT_DATE" '
57+ BEGIN { in_frontmatter=0; added=0 }
58+ NR==1 && /^---$/ { in_frontmatter=1; print; next }
59+ in_frontmatter && /^---$/ && !added { print "last-updated: " date; added=1; print; in_frontmatter=0; next }
60+ { print }
61+ ' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
6462 fi
6563 done
6664
You can’t perform that action at this time.
0 commit comments