Path change to make git Markdown not bork on & and spaces
This commit is contained in:
@@ -3,9 +3,13 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
CAMEL_CASE_RE = re.compile(r'(?<=[a-z])(?=[A-Z])')
|
||||
|
||||
|
||||
def read_title(markdown_path: Path) -> str:
|
||||
for line in markdown_path.read_text(encoding='utf-8').splitlines():
|
||||
if line.startswith('# '):
|
||||
@@ -13,11 +17,26 @@ def read_title(markdown_path: Path) -> str:
|
||||
return markdown_path.stem
|
||||
|
||||
|
||||
def humanize_token(token: str) -> str:
|
||||
return CAMEL_CASE_RE.sub(' ', token).strip()
|
||||
|
||||
|
||||
def display_section_name(directory_name: str) -> str:
|
||||
parts = [humanize_token(part) for part in directory_name.split('_') if part]
|
||||
if not parts:
|
||||
return directory_name
|
||||
if len(parts) == 1:
|
||||
return parts[0]
|
||||
if len(parts) == 2:
|
||||
return f'{parts[0]} & {parts[1]}'
|
||||
return f"{', '.join(parts[:-1])} & {parts[-1]}"
|
||||
|
||||
|
||||
def build_index(workshops_dir: Path) -> str:
|
||||
sections: list[str] = ['# Workshops Index']
|
||||
|
||||
for subdir in sorted(path for path in workshops_dir.iterdir() if path.is_dir()):
|
||||
sections.append(f'## {subdir.name}')
|
||||
sections.append(f'## {display_section_name(subdir.name)}')
|
||||
|
||||
markdown_files = sorted(subdir.glob('*.md'))
|
||||
if not markdown_files:
|
||||
|
||||
Reference in New Issue
Block a user