2021-02-20 14:03:54 +00:00
|
|
|
package shroom
|
2021-02-17 18:41:35 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2021-05-12 13:34:24 +00:00
|
|
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
2021-02-20 14:03:54 +00:00
|
|
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
2021-02-17 18:41:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// FetchTextPart tries to read text file of the given hypha. If there is no file, empty string is returned.
|
2021-02-20 14:03:54 +00:00
|
|
|
func FetchTextPart(h *hyphae.Hypha) (string, error) {
|
2021-02-17 18:41:35 +00:00
|
|
|
if h.TextPath == "" {
|
|
|
|
return "", nil
|
|
|
|
}
|
2021-07-02 08:29:55 +00:00
|
|
|
text, err := os.ReadFile(h.TextPath)
|
2021-02-17 18:41:35 +00:00
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return "", nil
|
|
|
|
} else if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return string(text), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetHeaderLinks() {
|
2021-05-09 09:36:39 +00:00
|
|
|
if userLinksHypha := hyphae.ByName(cfg.HeaderLinksHypha); !userLinksHypha.Exists {
|
2021-05-11 08:33:00 +00:00
|
|
|
cfg.SetDefaultHeaderLinks()
|
2021-02-17 18:41:35 +00:00
|
|
|
} else {
|
2021-07-02 08:29:55 +00:00
|
|
|
contents, err := os.ReadFile(userLinksHypha.TextPath)
|
2021-02-17 18:41:35 +00:00
|
|
|
if err != nil || len(contents) == 0 {
|
2021-05-11 08:33:00 +00:00
|
|
|
cfg.SetDefaultHeaderLinks()
|
2021-02-17 18:41:35 +00:00
|
|
|
} else {
|
|
|
|
text := string(contents)
|
2021-05-24 09:33:57 +00:00
|
|
|
cfg.ParseHeaderLinks(text)
|
2021-02-17 18:41:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|