herolib_python/_archive/lib/web/mdcollections/factory.py
2025-08-05 15:15:36 +02:00

26 lines
713 B
Python

import os
from pathlib import Path
from typing import Optional
from .mdcollections import MDCollections
def create_collections(path: Optional[str] = None) -> MDCollections:
"""
Factory function to create and initialize an MDCollections instance.
Args:
path: Optional path to scan for collections. Defaults to "data/markdown"
Returns:
Initialized MDCollections instance
Raises:
ValueError: If path is None
"""
if path is None:
raise ValueError("Path cannot be None")
# Expand ~ to home directory if present in path
expanded_path = os.path.expanduser(path)
return MDCollections(root_path=Path(expanded_path))