1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-02-07 14:40:16 +00:00
mycorrhiza/shroom/view.go

40 lines
910 B
Go
Raw Normal View History

2021-02-20 19:03:54 +05:00
package shroom
2021-02-17 23:41:35 +05:00
import (
"io/ioutil"
"os"
"github.com/bouncepaw/mycorrhiza/cfg"
2021-02-20 19:03:54 +05:00
"github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycomarkup/blocks"
2021-02-17 23:41:35 +05:00
)
// FetchTextPart tries to read text file of the given hypha. If there is no file, empty string is returned.
2021-02-20 19:03:54 +05:00
func FetchTextPart(h *hyphae.Hypha) (string, error) {
2021-02-17 23:41:35 +05:00
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 {
2021-05-11 13:33:00 +05:00
cfg.SetDefaultHeaderLinks()
2021-02-17 23:41:35 +05:00
} else {
contents, err := ioutil.ReadFile(userLinksHypha.TextPath)
if err != nil || len(contents) == 0 {
2021-05-11 13:33:00 +05:00
cfg.SetDefaultHeaderLinks()
2021-02-17 23:41:35 +05:00
} else {
text := string(contents)
cfg.ParseHeaderLinks(text, blocks.Rocketlink)
2021-02-17 23:41:35 +05:00
}
}
}