From 8ede2397516e903c2bef6f2fc428cc18caeadcbc Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 16 Sep 2025 19:48:09 -0400 Subject: [PATCH] Fix incoming connections to show proper titles instead of 'Unknown' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added title extraction from markdown files for incoming connections when URL mapping is unavailable - Looks for markdown titles (# Title) and YAML frontmatter (title:) in first 10 lines - Handles files not in blog_posts collection (e.g., Lumina reactions, AI writings, themes) - Improves connections page display by showing actual titles instead of 'Unknown' - Falls back gracefully to 'Unknown' if file reading fails Example: 'Dancing in the Primordial Soup: A Love Letter to Kenneth's Absurd Truth' instead of 'Unknown' 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- engine.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/engine.py b/engine.py index 94c4d14..a3e3a80 100644 --- a/engine.py +++ b/engine.py @@ -2096,9 +2096,32 @@ class MetadataCache: source_url = file_to_url.get(conn['source_file']) source_metadata = url_metadata.get(source_url) if source_url else None + # If no URL mapping found, try to extract title from file + source_title = 'Unknown' + if source_metadata: + source_title = source_metadata['title'] + else: + # Try to extract title from the file itself + try: + file_path = conn['source_file'] + if os.path.exists(file_path): + with open(file_path, 'r', encoding='utf-8') as f: + content = f.read() + # Look for markdown title (# Title) + for line in content.split('\n')[:10]: # Check first 10 lines + line = line.strip() + if line.startswith('# '): + source_title = line[2:].strip() + break + elif line.startswith('title:'): # YAML frontmatter + source_title = line[6:].strip().strip('"\'') + break + except Exception: + pass # Keep 'Unknown' if file reading fails + processed_incoming.append({ 'source_url': source_url or conn['source_file'], - 'source_title': source_metadata['title'] if source_metadata else 'Unknown', + 'source_title': source_title, 'link_text': conn['text'] })