Skip to content

Commit 66c10aa

Browse files
committed
fix
1 parent 63c3032 commit 66c10aa

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

scripts/update_readme.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import re
33
from datetime import datetime
4+
from urllib.parse import quote
45

56
# Directory where notebooks are stored
67
notebooks_dir = 'notebooks'
@@ -17,15 +18,19 @@
1718
new_base_url = "https://nbviewer.org/github/weijie-chen/Linear-Algebra-With-Python/blob/master/notebooks"
1819

1920
# 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})"
21+
def generate_lecture_link(filename):
22+
lecture_name = filename.replace('.ipynb', '')
23+
encoded_filename = quote(filename)
24+
return f"[{lecture_name}]({new_base_url}/{encoded_filename})"
2325

24-
# Get list of notebook files
25-
notebook_files = [f for f in os.listdir(notebooks_dir) if f.endswith('.ipynb')]
26+
# Get list of notebook files and sort them numerically by chapter
27+
notebook_files = sorted(
28+
[f for f in os.listdir(notebooks_dir) if f.endswith('.ipynb')],
29+
key=lambda x: int(re.search(r'\d+', x).group())
30+
)
2631

2732
# Create a new content section for the lectures
28-
lectures_section = "\n".join([generate_chapter_link(file) + "<br>" for file in sorted(notebook_files)])
33+
lectures_section = "\n".join([generate_lecture_link(file) + "<br>" for file in notebook_files])
2934

3035
# Update the lectures section in the README content
3136
content = re.sub(r'## Contents(.|\n)*?(?=##)', f'## Contents\n\n{lectures_section}\n\n', content, flags=re.DOTALL)

0 commit comments

Comments
 (0)