-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs_embed.go
More file actions
41 lines (35 loc) · 895 Bytes
/
docs_embed.go
File metadata and controls
41 lines (35 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package fkn
import (
"embed"
"fmt"
"strings"
)
//go:embed README.md docs/user-guide.md docs/why-not-make.md docs/releasing.md
var embeddedDocs embed.FS
var docPaths = map[string]string{
"readme": "README.md",
"user-guide": "docs/user-guide.md",
"why-not-make": "docs/why-not-make.md",
"comparison": "docs/why-not-make.md",
"releasing": "docs/releasing.md",
"release": "docs/releasing.md",
}
var primaryDocNames = []string{"readme", "user-guide", "why-not-make", "releasing"}
func DocNames() []string {
names := append([]string{}, primaryDocNames...)
return names
}
func Doc(name string) (string, error) {
if name == "" {
name = "readme"
}
path, ok := docPaths[strings.ToLower(name)]
if !ok {
return "", fmt.Errorf("unknown docs page %q", name)
}
raw, err := embeddedDocs.ReadFile(path)
if err != nil {
return "", err
}
return string(raw), nil
}