mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-12 13:30:26 +00:00
85c936d94a
'I do as the golint guides'
38 lines
952 B
Go
38 lines
952 B
Go
package shroom
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
|
)
|
|
|
|
// FetchTextPart tries to read text file of the given hypha. If there is no file, empty string is returned.
|
|
func FetchTextPart(h *hyphae.Hypha) (string, error) {
|
|
if h.TextPath == "" {
|
|
return "", nil
|
|
}
|
|
text, err := os.ReadFile(h.TextPath)
|
|
if os.IsNotExist(err) {
|
|
return "", nil
|
|
} else if err != nil {
|
|
return "", err
|
|
}
|
|
return string(text), nil
|
|
}
|
|
|
|
// SetHeaderLinks initializes header links by reading the configured hypha, if there is any, or resorting to default values.
|
|
func SetHeaderLinks() {
|
|
if userLinksHypha := hyphae.ByName(cfg.HeaderLinksHypha); !userLinksHypha.Exists {
|
|
cfg.SetDefaultHeaderLinks()
|
|
} else {
|
|
contents, err := os.ReadFile(userLinksHypha.TextPath)
|
|
if err != nil || len(contents) == 0 {
|
|
cfg.SetDefaultHeaderLinks()
|
|
} else {
|
|
text := string(contents)
|
|
cfg.ParseHeaderLinks(text)
|
|
}
|
|
}
|
|
}
|