parser.py•1.01 kB
"""Parser for Jekyll posts - handles both Markdown and AsciiDoc."""
import frontmatter
from pathlib import Path
from typing import Dict, Any
class PostParser:
"""Parse Jekyll posts with front matter."""
@staticmethod
def parse_post(file_path: Path) -> Dict[str, Any]:
"""
Parse a Jekyll post file.
Args:
file_path: Path to the post file
Returns:
Dictionary with 'metadata' and 'content' keys
"""
with open(file_path, 'r', encoding='utf-8') as f:
post = frontmatter.load(f)
return {
'metadata': dict(post.metadata),
'content': post.content,
'file_path': str(file_path),
'file_name': file_path.name,
'extension': file_path.suffix
}
@staticmethod
def is_valid_post(file_path: Path) -> bool:
"""Check if file is a valid post (.md or .adoc)."""
return file_path.suffix in ['.md', '.adoc'] and file_path.is_file()