@@ -243,8 +243,9 @@ def _read_wiki_context(wiki_dir: Path) -> tuple[str, list[str]]:
243243def _read_concept_briefs (wiki_dir : Path ) -> str :
244244 """Read existing concept pages and return compact one-line summaries.
245245
246- For each concept, skips YAML frontmatter, takes the first 150 chars of the
247- body (newlines collapsed to spaces), and formats as ``- {slug}: {brief}``.
246+ For each concept, reads the ``brief:`` field from YAML frontmatter if
247+ present; otherwise falls back to truncating the first 150 chars of the body
248+ (newlines collapsed to spaces). Formats each as ``- {slug}: {brief}``.
248249
249250 Returns "(none yet)" if the concepts directory is missing or empty.
250251 """
@@ -259,16 +260,23 @@ def _read_concept_briefs(wiki_dir: Path) -> str:
259260 lines : list [str ] = []
260261 for path in md_files :
261262 text = path .read_text (encoding = "utf-8" )
262- # Strip YAML frontmatter if present
263+ brief = ""
264+ body = text
263265 if text .startswith ("---" ):
264266 end = text .find ("---" , 3 )
265267 if end != - 1 :
266- text = text [end + 3 :]
267- body = text .strip ().replace ("\n " , " " )
268- brief = body [:150 ]
269- lines .append (f"- { path .stem } : { brief } " )
268+ fm = text [:end + 3 ]
269+ body = text [end + 3 :]
270+ for line in fm .split ("\n " ):
271+ if line .startswith ("brief:" ):
272+ brief = line [len ("brief:" ):].strip ()
273+ break
274+ if not brief :
275+ brief = body .strip ().replace ("\n " , " " )[:150 ]
276+ if brief :
277+ lines .append (f"- { path .stem } : { brief } " )
270278
271- return "\n " .join (lines )
279+ return "\n " .join (lines ) or "(none yet)"
272280
273281
274282def _find_source_filename (doc_name : str , kb_dir : Path ) -> str :
@@ -281,11 +289,14 @@ def _find_source_filename(doc_name: str, kb_dir: Path) -> str:
281289 return f"{ doc_name } .pdf"
282290
283291
284- def _write_summary (wiki_dir : Path , doc_name : str , source_file : str , summary : str ) -> None :
292+ def _write_summary (wiki_dir : Path , doc_name : str , source_file : str , summary : str , brief : str = "" ) -> None :
285293 """Write summary page with frontmatter."""
286294 summaries_dir = wiki_dir / "summaries"
287295 summaries_dir .mkdir (parents = True , exist_ok = True )
288- frontmatter = f"---\n sources: [{ source_file } ]\n ---\n \n "
296+ fm_lines = [f"sources: [{ source_file } ]" ]
297+ if brief :
298+ fm_lines .append (f"brief: { brief } " )
299+ frontmatter = "---\n " + "\n " .join (fm_lines ) + "\n ---\n \n "
289300 (summaries_dir / f"{ doc_name } .md" ).write_text (frontmatter + summary , encoding = "utf-8" )
290301
291302
@@ -298,7 +309,7 @@ def _sanitize_concept_name(name: str) -> str:
298309 return sanitized or "unnamed-concept"
299310
300311
301- def _write_concept (wiki_dir : Path , name : str , content : str , source_file : str , is_update : bool ) -> None :
312+ def _write_concept (wiki_dir : Path , name : str , content : str , source_file : str , is_update : bool , brief : str = "" ) -> None :
302313 """Write or update a concept page, managing the sources frontmatter."""
303314 concepts_dir = wiki_dir / "concepts"
304315 concepts_dir .mkdir (parents = True , exist_ok = True )
@@ -324,9 +335,22 @@ def _write_concept(wiki_dir: Path, name: str, content: str, source_file: str, is
324335 else :
325336 existing = f"---\n sources: [{ source_file } ]\n ---\n \n " + existing
326337 existing += f"\n \n { content } "
338+ if brief and existing .startswith ("---" ):
339+ end = existing .find ("---" , 3 )
340+ if end != - 1 :
341+ fm = existing [:end + 3 ]
342+ body = existing [end + 3 :]
343+ if "brief:" in fm :
344+ fm = re .sub (r"brief:.*" , f"brief: { brief } " , fm )
345+ else :
346+ fm = fm .replace ("---\n " , f"---\n brief: { brief } \n " , 1 )
347+ existing = fm + body
327348 path .write_text (existing , encoding = "utf-8" )
328349 else :
329- frontmatter = f"---\n sources: [{ source_file } ]\n ---\n \n "
350+ fm_lines = [f"sources: [{ source_file } ]" ]
351+ if brief :
352+ fm_lines .append (f"brief: { brief } " )
353+ frontmatter = "---\n " + "\n " .join (fm_lines ) + "\n ---\n \n "
330354 path .write_text (frontmatter + content , encoding = "utf-8" )
331355
332356
0 commit comments