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

Commit

Permalink
Create pages.py
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzroe authored Oct 25, 2024
1 parent 3358573 commit 7f3de37
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/scripts/pages.py
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)

0 comments on commit 7f3de37

Please sign in to comment.