Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
weijie-chen committed Aug 5, 2024
1 parent 63c3032 commit 66c10aa
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions scripts/update_readme.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import re
from datetime import datetime
from urllib.parse import quote

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

# Function to generate new lecture link
def generate_chapter_link(filename):
chapter_name = filename.replace('.ipynb', '')
return f"[{chapter_name}]({new_base_url}/{filename})"
def generate_lecture_link(filename):
lecture_name = filename.replace('.ipynb', '')
encoded_filename = quote(filename)
return f"[{lecture_name}]({new_base_url}/{encoded_filename})"

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

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

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

0 comments on commit 66c10aa

Please sign in to comment.