fix: robust lesson parsing for flexible home.md formats
This commit is contained in:
parent
097f2c5609
commit
be534f3512
|
|
@ -27,15 +27,17 @@ def get_lesson_names():
|
||||||
with open(home_file_path, 'r', encoding='utf-8') as f:
|
with open(home_file_path, 'r', encoding='utf-8') as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
|
|
||||||
parts = content.split('---Available_Lessons---')
|
# Use robust regex to split Available_Lessons
|
||||||
|
parts = re.split(r'-{3,}Available_Lessons-{3,}', content)
|
||||||
if len(parts) > 1:
|
if len(parts) > 1:
|
||||||
lesson_list_content = parts[1]
|
lesson_list_content = parts[1]
|
||||||
|
# Allow optional leading slash in /lesson/ prefix
|
||||||
lesson_links = re.findall(
|
lesson_links = re.findall(
|
||||||
r'\[([^\]]+)\]\(lesson/([^\)]+)\)', lesson_list_content
|
r'\[([^\]]+)\]\((?:/?lesson/)?([^\)]+)\)', lesson_list_content
|
||||||
)
|
)
|
||||||
if lesson_links:
|
if lesson_links:
|
||||||
for _link_text, filename in lesson_links:
|
for _link_text, slug in lesson_links:
|
||||||
lesson_names.append(filename.replace('.md', ''))
|
lesson_names.append(slug.replace('.md', ''))
|
||||||
return lesson_names
|
return lesson_names
|
||||||
|
|
||||||
# Fallback: alphabetical order
|
# Fallback: alphabetical order
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,8 @@ def _parse_lesson_links(home_content):
|
||||||
return []
|
return []
|
||||||
lesson_list_content = parts[-1]
|
lesson_list_content = parts[-1]
|
||||||
|
|
||||||
links = re.findall(r'\[([^\]]+)\]\((?:/lesson/)?([^\)]+)\)', lesson_list_content)
|
# Allow optional leading slash in /lesson/ prefix
|
||||||
|
links = re.findall(r'\[([^\]]+)\]\((?:/?lesson/)?([^\)]+)\)', lesson_list_content)
|
||||||
|
|
||||||
processed_links = []
|
processed_links = []
|
||||||
for title, slug in links:
|
for title, slug in links:
|
||||||
|
|
@ -582,6 +583,7 @@ def render_home_content():
|
||||||
if not home_content:
|
if not home_content:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
parts = home_content.split('---Available_Lessons---')
|
# Use robust regex to split Available_Lessons
|
||||||
|
parts = re.split(r'-{3,}Available_Lessons-{3,}', home_content)
|
||||||
main_content = parts[0] if parts else home_content
|
main_content = parts[0] if parts else home_content
|
||||||
return md.markdown(main_content, extensions=['fenced_code', 'tables', 'mdx_math'])
|
return md.markdown(main_content, extensions=['fenced_code', 'tables', 'mdx_math'])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue