|
| 1 | +import os |
1 | 2 | import re
|
2 | 3 | from datetime import datetime
|
3 | 4 |
|
| 5 | +# Directory where notebooks are stored |
| 6 | +notebooks_dir = 'notebooks' |
| 7 | + |
4 | 8 | # Read the README.md file
|
5 | 9 | with open('README.md', 'r') as file:
|
6 | 10 | content = file.read()
|
|
10 | 14 | content = re.sub(r"<font color='purple' size=2.5><i>Updated on .*</i></font>", updated_date, content)
|
11 | 15 |
|
12 | 16 | # 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)]) |
14 | 29 |
|
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) |
17 | 32 |
|
18 | 33 | # Write the updated content back to the README.md file
|
19 | 34 | with open('README.md', 'w') as file:
|
|
0 commit comments