github.com/linchen2chris/hugo@v0.0.0-20230307053224-cec209389705/helpers/docshelper.go (about)

     1  package helpers
     2  
     3  import (
     4  	"sort"
     5  
     6  	"github.com/alecthomas/chroma/v2/lexers"
     7  	"github.com/gohugoio/hugo/docshelper"
     8  )
     9  
    10  // This is is just some helpers used to create some JSON used in the Hugo docs.
    11  func init() {
    12  	docsProvider := func() docshelper.DocProvider {
    13  		var chromaLexers []any
    14  
    15  		sort.Sort(lexers.GlobalLexerRegistry.Lexers)
    16  
    17  		for _, l := range lexers.GlobalLexerRegistry.Lexers {
    18  
    19  			config := l.Config()
    20  
    21  			lexerEntry := struct {
    22  				Name    string
    23  				Aliases []string
    24  			}{
    25  				config.Name,
    26  				config.Aliases,
    27  			}
    28  
    29  			chromaLexers = append(chromaLexers, lexerEntry)
    30  
    31  		}
    32  
    33  		return docshelper.DocProvider{"chroma": map[string]any{"lexers": chromaLexers}}
    34  	}
    35  
    36  	docshelper.AddDocProviderFunc(docsProvider)
    37  }