File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff 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 * \[ ( .+ ) \] $ / )
You can’t perform that action at this time.
0 commit comments