From 04a567519f88e37773fd37a9388966aebb6780b8 Mon Sep 17 00:00:00 2001 From: Mohamed Elashri Date: Fri, 15 Nov 2024 20:59:18 -0500 Subject: [PATCH 1/8] Fix: Ensure awesome-lint compliance with badge and punctuation updates --- generate_readme.py | 57 ++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/generate_readme.py b/generate_readme.py index 12c6b88..5046515 100755 --- a/generate_readme.py +++ b/generate_readme.py @@ -9,6 +9,7 @@ def extract_repo(url): match = re.match(r'https://github\.com/([^/]+/[^/]+)', url) return match[1] if match else '' + def add_badges(lines): """Add GitHub badges to lines containing GitHub repository URLs.""" processed_lines = [] @@ -22,11 +23,11 @@ def add_badges(lines): processed_lines.append('') # Add a blank line # Add shields.io badges badges = [ - f' ![Last Commit](https://img.shields.io/github/last-commit/{repo_name})', - f'![License](https://img.shields.io/github/license/{repo_name})', - f'![Issues](https://img.shields.io/github/issues/{repo_name})', - f'![Stars](https://img.shields.io/github/stars/{repo_name})', - f'![Forks](https://img.shields.io/github/forks/{repo_name})', + f' ![Last Commit](https://img.shields.io/github/last-commit/{repo_name}?style=flat-square)', + f'![License](https://img.shields.io/github/license/{repo_name}?style=flat-square)', + f'![Issues](https://img.shields.io/github/issues/{repo_name}?style=flat-square)', + f'![Stars](https://img.shields.io/github/stars/{repo_name}?style=flat-square)', + f'![Forks](https://img.shields.io/github/forks/{repo_name}?style=flat-square)', '' ] processed_lines.extend(badges) @@ -36,30 +37,35 @@ def add_badges(lines): processed_lines.append(line) return processed_lines -def style_badges(lines): - """Add the 'flat-square' style to all image badges in the lines.""" - def replace_style(match): - alt_text = match.group(1) - url = match.group(2) - url += '&style=flat-square' if '?' in url else '?style=flat-square' - return f'![{alt_text}]({url})' - styled_lines = [] - pattern = re.compile(r'!\[([^\]]+)\]\(([^)]+)\)') +def ensure_punctuation(lines): + """Ensure all list item descriptions end with a period.""" + punctuated_lines = [] for line in lines: - styled_line = pattern.sub(replace_style, line) - styled_lines.append(styled_line) - return styled_lines + # Match lines that start with list items and have descriptions + if re.match(r'- \[.*?\]\(.*?\) - .*[^.]$', line): + line += '.' # Append a period + punctuated_lines.append(line) + return punctuated_lines + def remove_extra_parentheses(lines): """Remove extra closing parentheses at the end of image markdown links.""" corrected_lines = [] for line in lines: - # Match image links with potential extra closing parentheses corrected_line = re.sub(r'(!\[[^\]]*\]\([^\)]*\))\)+', r'\1', line) corrected_lines.append(corrected_line) return corrected_lines + +def add_awesome_badge(lines): + """Ensure the Awesome badge is correctly added.""" + badge = '[![Awesome](https://awesome.re/badge-flat.svg)](https://awesome.re)' + if lines and badge not in lines[0]: + lines.insert(0, badge) + return lines + + def main(): if len(sys.argv) != 2: print("Usage: python script.py ") @@ -70,13 +76,14 @@ def main(): with open(input_file, 'r', encoding='utf-8') as f: lines = [line.rstrip('\n') for line in f] - lines_with_badges = add_badges(lines) + lines = add_awesome_badge(lines) + lines = add_badges(lines) + lines = ensure_punctuation(lines) + lines = remove_extra_parentheses(lines) - lines_with_square_badges = style_badges(lines_with_badges) - - final_lines = remove_extra_parentheses(lines_with_square_badges) - - for line in final_lines: + for line in lines: print(line) -main() + +if __name__ == "__main__": + main() From 36b4f8319451a53617792266e23586df54c0fb69 Mon Sep 17 00:00:00 2001 From: Mohamed Elashri Date: Fri, 15 Nov 2024 21:02:46 -0500 Subject: [PATCH 2/8] Add manual run for the testing CI --- .github/workflows/test_readme.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_readme.yml b/.github/workflows/test_readme.yml index 867c97f..fd64730 100644 --- a/.github/workflows/test_readme.yml +++ b/.github/workflows/test_readme.yml @@ -5,7 +5,8 @@ on: branches: ['**'] paths: - '_README.md' - + workflow_dispatch: + jobs: test-readme: runs-on: ubuntu-latest From 5f5ef27a828352be5d4398f2e7bc5b0ebee8923b Mon Sep 17 00:00:00 2001 From: Mohamed Elashri Date: Fri, 15 Nov 2024 21:05:54 -0500 Subject: [PATCH 3/8] Add obsidian-zotlit The purpose also is to test the linter fix --- _README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/_README.md b/_README.md index a97d52d..1846fb7 100644 --- a/_README.md +++ b/_README.md @@ -69,6 +69,7 @@ Your help is much appreciated. If you want to add something or fix a problem, lo - [KeepZotero](https://github.com/yhmtsai/KeepZotero) - Zotero plugin to keep Zotero in the taskbar by changing close to minimize or disabling shortcuts. - [Zotero Addons](https://github.com/syt2/zotero-addons) - Zotero add-on to list and install add-ons in Zotero. - [zotero-arxiv-workflow](https://github.com/AllanChain/zotero-arxiv-workflow) - Zotero plugin to help you manage adding and updating papers from arXiv. +- [obsidian-zotlit](https://github.com/PKM-er/obsidian-zotlit) -Integration between Obsidian.md and Zotero ### Productivity - [Chartero](https://github.com/volatile-static/Chartero) - Zotero plugin to provide charts in Zotero. From acab6bbd6c89076269228f52c5a5bdb164846332 Mon Sep 17 00:00:00 2001 From: Mohamed Elashri Date: Fri, 15 Nov 2024 21:07:51 -0500 Subject: [PATCH 4/8] Remove duplicate obsidian-zotlit --- _README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/_README.md b/_README.md index 1846fb7..a97d52d 100644 --- a/_README.md +++ b/_README.md @@ -69,7 +69,6 @@ Your help is much appreciated. If you want to add something or fix a problem, lo - [KeepZotero](https://github.com/yhmtsai/KeepZotero) - Zotero plugin to keep Zotero in the taskbar by changing close to minimize or disabling shortcuts. - [Zotero Addons](https://github.com/syt2/zotero-addons) - Zotero add-on to list and install add-ons in Zotero. - [zotero-arxiv-workflow](https://github.com/AllanChain/zotero-arxiv-workflow) - Zotero plugin to help you manage adding and updating papers from arXiv. -- [obsidian-zotlit](https://github.com/PKM-er/obsidian-zotlit) -Integration between Obsidian.md and Zotero ### Productivity - [Chartero](https://github.com/volatile-static/Chartero) - Zotero plugin to provide charts in Zotero. From 0a34bba7495e0c96dba75d15ca51ccc7a52d02c7 Mon Sep 17 00:00:00 2001 From: Mohamed Elashri Date: Fri, 15 Nov 2024 21:10:37 -0500 Subject: [PATCH 5/8] Resolve duplicate links and enforce list formatting for awesome-lint compliance --- generate_readme.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/generate_readme.py b/generate_readme.py index 5046515..67b8878 100755 --- a/generate_readme.py +++ b/generate_readme.py @@ -42,7 +42,6 @@ def ensure_punctuation(lines): """Ensure all list item descriptions end with a period.""" punctuated_lines = [] for line in lines: - # Match lines that start with list items and have descriptions if re.match(r'- \[.*?\]\(.*?\) - .*[^.]$', line): line += '.' # Append a period punctuated_lines.append(line) @@ -61,11 +60,36 @@ def remove_extra_parentheses(lines): def add_awesome_badge(lines): """Ensure the Awesome badge is correctly added.""" badge = '[![Awesome](https://awesome.re/badge-flat.svg)](https://awesome.re)' - if lines and badge not in lines[0]: - lines.insert(0, badge) + if any(badge in line for line in lines): + return lines + lines.insert(0, badge) return lines +def fix_list_item_format(lines): + """Ensure list items use a dash separator between link and description.""" + formatted_lines = [] + for line in lines: + if re.match(r'- \[.*?\]\(.*?\) .*', line): + line = re.sub(r'(\]\(.*?\)) ', r'\1 - ', line) # Ensure a dash after the link + formatted_lines.append(line) + return formatted_lines + + +def remove_duplicate_links(lines): + """Remove duplicate links in the markdown.""" + seen_links = set() + deduplicated_lines = [] + for line in lines: + if match := re.search(r'\((https?://[^\)]+)\)', line): + link = match.group(1) + if link in seen_links: + continue # Skip duplicate link + seen_links.add(link) + deduplicated_lines.append(line) + return deduplicated_lines + + def main(): if len(sys.argv) != 2: print("Usage: python script.py ") @@ -79,6 +103,8 @@ def main(): lines = add_awesome_badge(lines) lines = add_badges(lines) lines = ensure_punctuation(lines) + lines = fix_list_item_format(lines) + lines = remove_duplicate_links(lines) lines = remove_extra_parentheses(lines) for line in lines: From b55c8df426e2cfe38d325564f359bee546a4b6a4 Mon Sep 17 00:00:00 2001 From: Mohamed Elashri Date: Fri, 15 Nov 2024 21:45:15 -0500 Subject: [PATCH 6/8] Add more triggering paths --- .github/workflows/test_readme.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test_readme.yml b/.github/workflows/test_readme.yml index fd64730..08e18b3 100644 --- a/.github/workflows/test_readme.yml +++ b/.github/workflows/test_readme.yml @@ -5,6 +5,8 @@ on: branches: ['**'] paths: - '_README.md' + - 'generate_readme.py' + - '.github/workflows/test-readme.yml' workflow_dispatch: jobs: From 158e9072e456709209393f15401bba036be6892d Mon Sep 17 00:00:00 2001 From: Mohamed Elashri Date: Fri, 15 Nov 2024 22:08:26 -0500 Subject: [PATCH 7/8] Update generate_readme.py --- generate_readme.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/generate_readme.py b/generate_readme.py index 67b8878..2438efa 100755 --- a/generate_readme.py +++ b/generate_readme.py @@ -60,8 +60,10 @@ def remove_extra_parentheses(lines): def add_awesome_badge(lines): """Ensure the Awesome badge is correctly added.""" badge = '[![Awesome](https://awesome.re/badge-flat.svg)](https://awesome.re)' + # Check if the badge already exists if any(badge in line for line in lines): return lines + # Add the badge at the top if not present lines.insert(0, badge) return lines From 56cefc63c6f1b7ebd98afe13c7b350484a2a39ee Mon Sep 17 00:00:00 2001 From: Mohamed Elashri Date: Fri, 15 Nov 2024 22:11:32 -0500 Subject: [PATCH 8/8] remove duplication in first line --- generate_readme.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/generate_readme.py b/generate_readme.py index 2438efa..c562113 100755 --- a/generate_readme.py +++ b/generate_readme.py @@ -59,11 +59,13 @@ def remove_extra_parentheses(lines): def add_awesome_badge(lines): """Ensure the Awesome badge is correctly added.""" - badge = '[![Awesome](https://awesome.re/badge-flat.svg)](https://awesome.re)' - # Check if the badge already exists - if any(badge in line for line in lines): - return lines + # Check for an existing "Awesome" badge in the lines + for line in lines: + if "https://awesome.re" in line: + return lines # Badge already exists; do nothing + # Add the badge at the top if not present + badge = '[![Awesome](https://awesome.re/badge-flat.svg)](https://awesome.re)' lines.insert(0, badge) return lines @@ -83,10 +85,11 @@ def remove_duplicate_links(lines): seen_links = set() deduplicated_lines = [] for line in lines: + # Check for links in the current line if match := re.search(r'\((https?://[^\)]+)\)', line): link = match.group(1) - if link in seen_links: - continue # Skip duplicate link + if link in seen_links and "https://awesome.re" not in line: + continue # Skip duplicate links (but don't remove Awesome badge) seen_links.add(link) deduplicated_lines.append(line) return deduplicated_lines