-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathfrontmatter.py
More file actions
27 lines (21 loc) · 886 Bytes
/
frontmatter.py
File metadata and controls
27 lines (21 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from pathlib import Path
from typing import Dict, Optional, Tuple
import frontmatter
from sqlite_rag.extractors.base import MetadataExtractor
class FrontmatterExtractor(MetadataExtractor):
"""Extracts frontmatter from markdown files."""
def extract(
self, content: str, file_path: Optional[Path] = None
) -> Tuple[str, Dict]:
"""Extract frontmatter from markdown content."""
try:
post = frontmatter.loads(content)
clean_content = post.content
metadata = dict(post.metadata)
return clean_content, metadata
except Exception:
# If frontmatter parsing fails, return original content
return content, {}
def supports_file_type(self, file_extension: str) -> bool:
"""Support markdown files."""
return file_extension.lower() in [".md", ".mdx", ".txt"]