Skip to content

Commit cbb135a

Browse files
committed
change link name
1 parent 6b5bd27 commit cbb135a

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

scripts/update_readme.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import os
12
import re
23
from datetime import datetime
34

5+
# Directory where notebooks are stored
6+
notebooks_dir = 'notebooks'
7+
48
# Read the README.md file
59
with open('README.md', 'r') as file:
610
content = file.read()
@@ -10,10 +14,21 @@
1014
content = re.sub(r"<font color='purple' size=2.5><i>Updated on .*</i></font>", updated_date, content)
1115

1216
# Define the new base URL for nbviewer links
13-
new_base_url = "https://nbviewer.org/github/weijie-chen/Linear-Algebra-With-Python/blob/master/notebooks/Chapter"
17+
new_base_url = "https://nbviewer.org/github/weijie-chen/Linear-Algebra-With-Python/blob/master/notebooks"
18+
19+
# Function to generate new lecture link
20+
def generate_chapter_link(filename):
21+
chapter_name = filename.replace('.ipynb', '')
22+
return f"[{chapter_name}]({new_base_url}/{filename})"
23+
24+
# Get list of notebook files
25+
notebook_files = [f for f in os.listdir(notebooks_dir) if f.endswith('.ipynb')]
26+
27+
# Create a new content section for the lectures
28+
lectures_section = "\n".join([generate_chapter_link(file) + "<br>" for file in sorted(notebook_files)])
1429

15-
# Update nbviewer links
16-
content = re.sub(r"https://nbviewer.jupyter.org/github/[^/]+/[^/]+/blob/[^/]+/Chapter[^\s]+", lambda match: re.sub(r"https://nbviewer.jupyter.org/github/[^/]+/[^/]+/blob/[^/]+/Chapter", new_base_url, match.group(0)), content)
30+
# Update the lectures section in the README content
31+
content = re.sub(r'## Contents(.|\n)*?(?=##)', f'## Contents\n\n{lectures_section}\n\n', content, flags=re.DOTALL)
1732

1833
# Write the updated content back to the README.md file
1934
with open('README.md', 'w') as file:

0 commit comments

Comments
 (0)