@@ -14,22 +14,24 @@ import (
1414func (l Linter ) lintMetadata (f * core.File ) error {
1515 metadata := make (map [string ]any )
1616
17- _ , err := frontmatter .Parse (strings .NewReader (f .Content ), & metadata )
17+ body , err := frontmatter .Parse (strings .NewReader (f .Content ), & metadata )
1818 if errors .Is (err , frontmatter .ErrNotFound ) {
19- // No front matter found, return the original content.
2019 return nil
2120 } else if err != nil {
2221 return err
2322 }
2423
25- seen := make (map [string ]int )
24+ frontmatter , fmErr := extractFrontMatter (f .Content , string (body ))
25+ if fmErr != nil {
26+ return fmErr
27+ }
28+
2629 for key , value := range metadata {
2730 if s , ok := value .(string ); ok {
28- i , line := findLineBySubstring ( f . Content , s , seen )
31+ i , _ := findBestLineBySubstring ( frontmatter , s )
2932 if i < 0 {
30- return core . NewE100 ( f . Path , fmt . Errorf ( "'%s' not found" , s ))
33+ continue
3134 }
32- seen [line ] = i
3335
3436 scope := "text.frontmatter." + key + f .RealExt
3537 block := nlp .NewLinedBlock (f .Content , s , scope , i - 1 )
@@ -43,3 +45,11 @@ func (l Linter) lintMetadata(f *core.File) error {
4345
4446 return nil
4547}
48+
49+ func extractFrontMatter (file , body string ) (string , error ) {
50+ startIndex := strings .Index (file , body )
51+ if startIndex == - 1 {
52+ return "" , fmt .Errorf ("body not found in the file" )
53+ }
54+ return file [:startIndex ], nil
55+ }
0 commit comments