mycorrhiza/shroom/view.go
2021-05-11 13:33:00 +05:00

39 lines
909 B
Go

package shroom
import (
"github.com/bouncepaw/mycorrhiza/cfg"
"io/ioutil"
"os"
"github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/markup"
)
// 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 := ioutil.ReadFile(h.TextPath)
if os.IsNotExist(err) {
return "", nil
} else if err != nil {
return "", err
}
return string(text), nil
}
func SetHeaderLinks() {
if userLinksHypha := hyphae.ByName(cfg.HeaderLinksHypha); !userLinksHypha.Exists {
cfg.SetDefaultHeaderLinks()
} else {
contents, err := ioutil.ReadFile(userLinksHypha.TextPath)
if err != nil || len(contents) == 0 {
cfg.SetDefaultHeaderLinks()
} else {
text := string(contents)
cfg.ParseHeaderLinks(text, markup.Rocketlink)
}
}
}