Skip to content

Commit 4787d0a

Browse files
committed
fix: llm page title resolution
1 parent 5647cea commit 4787d0a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/internal/mdx.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -698,14 +698,16 @@ export function remarkDefaultFrontmatter() {
698698

699699
if (hasTitle && hasDescription) return
700700

701-
// Find first h1
702-
const h1 = tree.children.find(
701+
// Find first heading (prefer h1, fall back to first heading of any depth)
702+
const heading = (tree.children.find(
703703
(node) => node.type === 'heading' && (node as { depth: number }).depth === 1,
704-
) as { type: 'heading'; children: { type: string; value?: string }[] } | undefined
705-
if (!h1) return
704+
) ?? tree.children.find((node) => node.type === 'heading')) as
705+
| { type: 'heading'; children: { type: string; value?: string }[] }
706+
| undefined
707+
if (!heading) return
706708

707709
// Extract text content
708-
const textContent = h1.children.map((child) => child.value ?? '').join('')
710+
const textContent = heading.children.map((child) => child.value ?? '').join('')
709711

710712
// Parse title and description: "My Title [Description here]"
711713
const match = textContent.match(/^(.+?)\s*\[(.+)\]$/)

0 commit comments

Comments
 (0)