Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 7f3de37

Browse files
authoredOct 25, 2024··
Create pages.py
1 parent 3358573 commit 7f3de37

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
 

‎.github/scripts/pages.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import re
2+
import os
3+
import subprocess
4+
5+
# Step 1: Read the content of index.md
6+
with open('../../index.md', 'r', encoding='utf-8') as file:
7+
index_content = file.read()
8+
9+
# Step 2: Remove the block ---
10+
index_content = re.sub(r'---\nlayout: page\nhide_title: true\nhide: true\n---\n', '', index_content)
11+
12+
# Step 3: Get the repository name using Git
13+
try:
14+
repo_name = subprocess.check_output(['git', 'config', '--get', 'remote.origin.url']).decode('utf-8').strip()
15+
repo_name = repo_name.split('/')[-1].replace('.git', '')
16+
except subprocess.CalledProcessError:
17+
repo_name = 'not found repository name'
18+
19+
# Step 4: Replace the content of the ### Web Flasher block
20+
index_content = re.sub(r'(### Web Flasher\n)(.*?)(?=\n# |\n## |\n### |\n#### |\n##### )',
21+
rf'\1\nGo to [xyzroe.cc/{repo_name}](https://xyzroe.cc/{repo_name}).\n',
22+
index_content, flags=re.DOTALL)
23+
24+
# Step 5: Check if the file README.md exists
25+
if os.path.exists('../../README.md'):
26+
# Step 6: Delete the file if it exists
27+
os.remove('../../README.md')
28+
29+
# Step 6: Create a list to store the content of README.md and add the title
30+
readme_content = []
31+
readme_content.append(f"# {repo_name}\n")
32+
33+
# Step 7: Add the modified content from index.md to README.md
34+
readme_content.append(index_content)
35+
36+
# Step 8: Save the changes to README.md
37+
with open('../../README.md', 'w', encoding='utf-8') as file:
38+
file.writelines(readme_content)

0 commit comments

Comments
 (0)
This repository has been archived.