Skip to content

Commit fb5be18

Browse files
committed
Update README auto updates
1 parent 16ea973 commit fb5be18

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

.github/workflows/update-leetcode-grid.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ jobs:
3232
run: |
3333
git config --local user.name "github-actions[bot]"
3434
git config --local user.email "github-actions[bot]@users.noreply.github.com"
35-
git add README.md
35+
git add README.md Site_README.md
3636
git diff-index --quiet HEAD || git commit -m "[Auto] Update LeetCode README table"
3737
git push

Scripts/update_project_readme.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,37 +62,42 @@ def generate_table_rows(problems, badge_func):
6262
for slug, number, title, difficulty, tags in problems:
6363
diff_badge = badge_func(difficulty)
6464
tags_str = ", ".join(tags)
65-
solution_link = f"https://leetcode.romitsagu.com/solutions/leetcode{number}/"
65+
solution_link = f"https://leetcode.romitsagu.com/solutions/{number}/"
6666
icon_md = f"[{LINK_ICON}]({solution_link})"
6767
rows.append(f"| {title} | {icon_md} | {diff_badge} | {tags_str} |")
6868
return "\n".join(rows)
6969

7070
def update_readme(readme_path, rows_str):
71-
"""Update the README table; creates one if not present."""
71+
"""Update the README table; replaces existing table completely, or creates a new one."""
7272
if not readme_path.exists():
7373
raise FileNotFoundError(f"{readme_path} does not exist")
7474

7575
readme_text = readme_path.read_text()
76-
# Match the full table
76+
77+
# Match full table: header + separator + any number of rows
7778
table_pattern = re.compile(
78-
r'(\| Problem \| Solution \| Difficulty \| Tags \s*\|\n\|[-| ]+\|\n)(.*?)(?=\n\| |\Z)',
79+
r'(\| Problem \| Solution \| Difficulty \| Tags \s*\|\n' # header
80+
r'\|[-| ]+\|\n)' # separator
81+
r'(?:\|.*\|\n?)*', # rows
7982
re.DOTALL
8083
)
8184

85+
new_table = (
86+
"| Problem | Solution | Difficulty | Tags |\n"
87+
"|---------|---------|------------|------|\n"
88+
+ rows_str + "\n"
89+
)
90+
8291
if table_pattern.search(readme_text):
83-
updated_text = table_pattern.sub(r"\1" + rows_str, readme_text)
92+
updated_text = table_pattern.sub(new_table, readme_text)
8493
print(f"✅ Updated table rows in {readme_path.name}")
8594
else:
86-
new_table = (
87-
"| Problem | Solution | Difficulty | Tags |\n"
88-
"|---------|---------|------------|------|\n"
89-
+ rows_str
90-
)
9195
updated_text = readme_text.strip() + "\n\n" + new_table
9296
print(f"✅ Added new table in {readme_path.name}")
9397

9498
readme_path.write_text(updated_text)
9599

100+
96101
def main():
97102
problems = []
98103

0 commit comments

Comments
 (0)