This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import re | ||
import os | ||
import subprocess | ||
|
||
# Step 1: Read the content of index.md | ||
with open('../../index.md', 'r', encoding='utf-8') as file: | ||
index_content = file.read() | ||
|
||
# Step 2: Remove the block --- | ||
index_content = re.sub(r'---\nlayout: page\nhide_title: true\nhide: true\n---\n', '', index_content) | ||
|
||
# Step 3: Get the repository name using Git | ||
try: | ||
repo_name = subprocess.check_output(['git', 'config', '--get', 'remote.origin.url']).decode('utf-8').strip() | ||
repo_name = repo_name.split('/')[-1].replace('.git', '') | ||
except subprocess.CalledProcessError: | ||
repo_name = 'not found repository name' | ||
|
||
# Step 4: Replace the content of the ### Web Flasher block | ||
index_content = re.sub(r'(### Web Flasher\n)(.*?)(?=\n# |\n## |\n### |\n#### |\n##### )', | ||
rf'\1\nGo to [xyzroe.cc/{repo_name}](https://xyzroe.cc/{repo_name}).\n', | ||
index_content, flags=re.DOTALL) | ||
|
||
# Step 5: Check if the file README.md exists | ||
if os.path.exists('../../README.md'): | ||
# Step 6: Delete the file if it exists | ||
os.remove('../../README.md') | ||
|
||
# Step 6: Create a list to store the content of README.md and add the title | ||
readme_content = [] | ||
readme_content.append(f"# {repo_name}\n") | ||
|
||
# Step 7: Add the modified content from index.md to README.md | ||
readme_content.append(index_content) | ||
|
||
# Step 8: Save the changes to README.md | ||
with open('../../README.md', 'w', encoding='utf-8') as file: | ||
file.writelines(readme_content) |