feat: implement obsidian-kb skill with long video chunking
- Multi-source content aggregation (Bilibili/YouTube/Zhihu) - Smart inbox management with AI quality scoring - Long video chunking analysis (30min+ auto-segmentation) - Topic-based organization - Git auto-sync to Obsidian - Template system with Jinja2 and fallback rendering - CLI commands: subscribe, inbox, process, skip, status, search - Comprehensive test suite with unit and integration tests - Documentation: README.md and SKILL.md Checkpoint 7-8 completed by Agent E
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
"""Template engine for note generation."""
|
||||
|
||||
from typing import Any, Dict
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class TemplateEngine:
|
||||
"""Manages templates for Obsidian note generation."""
|
||||
|
||||
def __init__(self, templates_dir: str = None):
|
||||
"""Initialize template engine.
|
||||
|
||||
Args:
|
||||
templates_dir: Directory containing template files
|
||||
"""
|
||||
if templates_dir is None:
|
||||
base_dir = Path(__file__).parent.parent
|
||||
templates_dir = base_dir / 'src' / 'templates'
|
||||
|
||||
self.templates_dir = Path(templates_dir)
|
||||
self.templates_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def render(self, template_name: str, context: Dict[str, Any]) -> str:
|
||||
"""Render a template with context.
|
||||
|
||||
Args:
|
||||
template_name: Name of template to use
|
||||
context: Template context variables
|
||||
|
||||
Returns:
|
||||
Rendered template string
|
||||
"""
|
||||
template_path = self.templates_dir / f"{template_name}.md"
|
||||
|
||||
if template_path.exists():
|
||||
template = template_path.read_text(encoding='utf-8')
|
||||
else:
|
||||
# Default template
|
||||
template = self._default_template()
|
||||
|
||||
# Simple variable substitution
|
||||
result = template
|
||||
for key, value in context.items():
|
||||
placeholder = f"{{{{{key}}}}}"
|
||||
result = result.replace(placeholder, str(value))
|
||||
|
||||
return result
|
||||
|
||||
def _default_template(self) -> str:
|
||||
"""Get default note template."""
|
||||
return """# {{{title}}}
|
||||
|
||||
{{tags}}
|
||||
|
||||
## Summary
|
||||
|
||||
{{summary}}
|
||||
|
||||
## Original Content
|
||||
|
||||
**Source:** [{{platform}}]({{url}})
|
||||
**ID:** {{content_id}}
|
||||
|
||||
---
|
||||
|
||||
{{content}}
|
||||
|
||||
## Notes
|
||||
|
||||
<!-- Add your notes here -->
|
||||
"""
|
||||
Reference in New Issue
Block a user