diff --git a/.github/workflows/generate-readme.yml b/.github/workflows/generate-readme.yml new file mode 100644 index 0000000..487bc1d --- /dev/null +++ b/.github/workflows/generate-readme.yml @@ -0,0 +1,32 @@ +name: Update README + +on: + push: + branches: + - main + paths: + - '_README.md' + + pull_request: + branches: ['**'] + +jobs: + update-readme: + if: ${{ github.actor != 'github-actions[bot]' }} + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Generate README.md + run: | + python3 generate_readme.py _README.md > README.md + + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: 'Auto-update README.md [skip ci]' + file_pattern: README.md + diff --git a/Contributing.md b/CONTRIBUTING.md similarity index 79% rename from Contributing.md rename to CONTRIBUTING.md index b0d15c4..4cbf502 100644 --- a/Contributing.md +++ b/CONTRIBUTING.md @@ -4,11 +4,11 @@ Please note that this project is released with a [Contributor Code of Conduct](c Ensure your pull request adheres to the following guidelines: -- Edit and modify the `README.md` file. +- Edit and modify the `_README.md` file. `README.md` is automatically generated from this file. - Ensure that the project you submit does not duplicate existing entries. - Ensuring that the items you submit have at least working documentation for the description. - Ensure that you add new item in alphabetical order -- Ensure that the new item have correct category. suggest new one if you find suitable +- Ensure that the new item have correct category. Suggest new one if you find suitable - Submit a separate PR for each item. - Format the PR title as `Add item: item name`/`Fix item: item name`. diff --git a/README.md b/_README.md similarity index 99% rename from README.md rename to _README.md index 079c353..819aa97 100644 --- a/README.md +++ b/_README.md @@ -96,4 +96,4 @@ Your help is much appreciated. If you want to add something or fix a problem, lo ## Contributing -Please see [contributing.md](contributing.md) for details on how to contribute to this awesome list. +Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to this awesome list. diff --git a/generate_readme.py b/generate_readme.py new file mode 100755 index 0000000..12c6b88 --- /dev/null +++ b/generate_readme.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 + +import re +import sys + + +def extract_repo(url): + """Extract the GitHub repository name from the 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 = [] + for line in lines: + if 'https://github.com/' in line: + if url_match := re.search(r'https://github\.com/\S+', line): + repo_url = url_match[0] + repo_name = extract_repo(repo_url) + processed_lines.append(line) + if repo_name: + 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})', + '' + ] + processed_lines.extend(badges) + else: + processed_lines.append(line) + else: + 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'!\[([^\]]+)\]\(([^)]+)\)') + for line in lines: + styled_line = pattern.sub(replace_style, line) + styled_lines.append(styled_line) + return styled_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 main(): + if len(sys.argv) != 2: + print("Usage: python script.py ") + sys.exit(1) + + input_file = sys.argv[1] + + 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_with_square_badges = style_badges(lines_with_badges) + + final_lines = remove_extra_parentheses(lines_with_square_badges) + + for line in final_lines: + print(line) + +main()