Skip to content

Commit 4bb6c5d

Browse files
committed
update ci
1 parent 1e50d26 commit 4bb6c5d

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

.github/workflows/update-last-updated.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)