|
1 | 1 | import os
|
2 | 2 | import re
|
3 | 3 | from datetime import datetime
|
| 4 | +from urllib.parse import quote |
4 | 5 |
|
5 | 6 | # Directory where notebooks are stored
|
6 | 7 | notebooks_dir = 'notebooks'
|
|
17 | 18 | new_base_url = "https://nbviewer.org/github/weijie-chen/Linear-Algebra-With-Python/blob/master/notebooks"
|
18 | 19 |
|
19 | 20 | # 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})" |
23 | 25 |
|
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 | +) |
26 | 31 |
|
27 | 32 | # 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]) |
29 | 34 |
|
30 | 35 | # Update the lectures section in the README content
|
31 | 36 | content = re.sub(r'## Contents(.|\n)*?(?=##)', f'## Contents\n\n{lectures_section}\n\n', content, flags=re.DOTALL)
|
|
0 commit comments