Skip to content

Commit

Permalink
chore(script): Update script to insert IDs without leading zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
euchangxian committed Oct 10, 2024
1 parent dd36e0d commit 2c6324c
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions update_readme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,15 @@ update_table() {
in_table && /^\| *:?-+:? *\| *:?-+:? *\| *:?-+:? *\|/ { print; next }
in_table && /^\|/ {
split($0, a, "|")
gsub(/^[ \t]+|[ \t]+$/, "", a[2]) # Trim whitespace
if (a[2] == num) {
if (a[2] + 0 == num) {
if (index($0, icon) == 0) { # If icon not present, add it
gsub(/\|[ \t]*$/, "", $0) # Remove trailing |
printf("%s %s |\n", $0, icon)
} else { # If icon present, keep existing line
print $0
}
updated = 1
} else if (a[2] > num && !updated) {
} else if ((a[2] + 0 > num) && !updated) {
printf("| %s | %s | %s |\n", num, name, icon)
print $0
updated = 1
Expand Down Expand Up @@ -96,7 +95,7 @@ update_table() {
# Process changed files
echo "$CHANGED_SOLUTIONS" | while read -r file; do
if [[ $file =~ ([^/]+)/([0-9]{4})-([^/]+)/Solution\.(.+)$ ]]; then
NUMBER=${BASH_REMATCH[2]}
NUMBER=$((10#${BASH_REMATCH[2]})) # Convert to base 10 to drop leading zeroes.
PROBLEM_NAME=${BASH_REMATCH[3]}
EXTENSION=${BASH_REMATCH[4]}
LANGUAGE_ICON=$(get_language_icon_with_link "$EXTENSION" "$file")
Expand Down

0 comments on commit 2c6324c

Please sign in to comment.