github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/docs.go (about) 1 package main 2 3 import ( 4 "embed" 5 "fmt" 6 "strings" 7 8 "github.com/lmorg/murex/builtins/docs" 9 "github.com/lmorg/murex/debug" 10 ) 11 12 //go:embed docs/apis/*.md 13 //go:embed docs/changelog/*.md 14 //go:embed docs/commands/*.md 15 //go:embed docs/events/*.md 16 //go:embed docs/mkarray/*.md 17 //go:embed docs/optional/*.md 18 //go:embed docs/parser/*.md 19 //go:embed docs/types/*.md 20 //go:embed docs/user-guide/*.md 21 //go:embed docs/variables/*.md 22 var docsEmbeded embed.FS 23 24 func init() { 25 docs.Definition = docsImport 26 } 27 28 func docsImport(path string) []byte { 29 if !strings.Contains(path, "/") { 30 path = "commands/" + path 31 } 32 path = fmt.Sprintf("docs/%s.md", path) 33 34 if debug.Enabled { 35 // in debug mode lets output the actual error 36 b, err := docsEmbeded.ReadFile(path) 37 if err != nil { 38 return append([]byte("error: "), []byte(err.Error())...) 39 } 40 return b 41 } 42 43 b, _ := docsEmbeded.ReadFile(path) 44 return b 45 }