Merge pull request #23 from she3o/general-improvements
General improvements
This commit is contained in:
commit
95a97071f7
|
|
@ -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
|
||||
|
||||
|
|
@ -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`.
|
||||
|
||||
|
|
@ -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.
|
||||
|
|
@ -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' ',
|
||||
f'',
|
||||
f'',
|
||||
f'',
|
||||
f'',
|
||||
''
|
||||
]
|
||||
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''
|
||||
|
||||
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 <input_markdown_file>")
|
||||
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()
|
||||
Loading…
Reference in New Issue