55
66from frontmatter import Post
77
8- from basic_memory .file_utils import has_frontmatter , remove_frontmatter
8+ from basic_memory .file_utils import has_frontmatter , remove_frontmatter , parse_frontmatter
99from basic_memory .markdown import EntityMarkdown
1010from basic_memory .models import Entity
1111from basic_memory .models import Observation as ObservationModel
@@ -74,15 +74,21 @@ async def schema_to_markdown(schema: Any) -> Post:
7474 """
7575 # Extract content and metadata
7676 content = schema .content or ""
77- frontmatter_metadata = dict (schema .entity_metadata or {})
77+ entity_metadata = dict (schema .entity_metadata or {})
7878
7979 # if the content contains frontmatter, remove it and merge
8080 if has_frontmatter (content ):
81+ content_frontmatter = parse_frontmatter (content )
8182 content = remove_frontmatter (content )
8283
84+ # Merge content frontmatter with entity metadata
85+ # (entity_metadata takes precedence for conflicts)
86+ content_frontmatter .update (entity_metadata )
87+ entity_metadata = content_frontmatter
88+
8389 # Remove special fields for ordered frontmatter
8490 for field in ["type" , "title" , "permalink" ]:
85- frontmatter_metadata .pop (field , None )
91+ entity_metadata .pop (field , None )
8692
8793 # Create Post with fields ordered by insert order
8894 post = Post (
@@ -94,7 +100,7 @@ async def schema_to_markdown(schema: Any) -> Post:
94100 if schema .permalink :
95101 post .metadata ["permalink" ] = schema .permalink
96102
97- if frontmatter_metadata :
98- post .metadata .update (frontmatter_metadata )
103+ if entity_metadata :
104+ post .metadata .update (entity_metadata )
99105
100106 return post
0 commit comments