@@ -289,21 +289,42 @@ func extractWorkflowNameFromFile(filePath string) (string, error) {
289289 return "" , err
290290 }
291291
292- // Extract markdown content (excluding frontmatter)
293- result , err := parser .ExtractFrontmatterFromContent (string (content ))
294- if err != nil {
295- return "" , err
296- }
297-
298- // Look for first H1 header
299- lines := strings .SplitSeq (result .Markdown , "\n " )
292+ // Scan lines directly: skip frontmatter block (between --- delimiters) without
293+ // YAML parsing, then find the first H1 header. This avoids the cost of a full
294+ // yaml.Unmarshal which is unnecessary when we only need the H1 title.
295+ //
296+ // Frontmatter is only recognised when "---" appears on the very first line,
297+ // matching the behaviour of ExtractFrontmatterFromContent.
298+ lines := strings .SplitSeq (string (content ), "\n " )
299+ firstLine := true
300+ inFrontmatter := false
301+ pastFrontmatter := false
300302 for line := range lines {
301- line = strings .TrimSpace (line )
302- if strings .HasPrefix (line , "# " ) {
303- return strings .TrimSpace (line [2 :]), nil
303+ trimmed := strings .TrimSpace (line )
304+ if firstLine {
305+ firstLine = false
306+ if trimmed == "---" {
307+ inFrontmatter = true
308+ continue
309+ }
310+ // No frontmatter on first line; treat the entire file as markdown.
311+ pastFrontmatter = true
312+ } else if inFrontmatter && ! pastFrontmatter {
313+ if trimmed == "---" {
314+ pastFrontmatter = true
315+ }
316+ continue
317+ }
318+ if pastFrontmatter && strings .HasPrefix (trimmed , "# " ) {
319+ return strings .TrimSpace (trimmed [2 :]), nil
304320 }
305321 }
306322
323+ // Unclosed frontmatter is an error (consistent with ExtractFrontmatterFromContent).
324+ if inFrontmatter && ! pastFrontmatter {
325+ return "" , errors .New ("frontmatter not properly closed" )
326+ }
327+
307328 // No H1 header found, generate default name from filename
308329 baseName := filepath .Base (filePath )
309330 baseName = strings .TrimSuffix (baseName , filepath .Ext (baseName ))
0 commit comments