2021-02-20 14:03:54 +00:00
|
|
|
package shroom
|
2021-02-17 18:41:35 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
|
2021-02-20 14:03:54 +00:00
|
|
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
2021-02-17 18:41:35 +00:00
|
|
|
"github.com/bouncepaw/mycorrhiza/markup"
|
|
|
|
"github.com/bouncepaw/mycorrhiza/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
text, err := ioutil.ReadFile(h.TextPath)
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return "", nil
|
|
|
|
} else if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return string(text), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetHeaderLinks() {
|
2021-02-20 14:03:54 +00:00
|
|
|
if userLinksHypha := hyphae.ByName(util.HeaderLinksHypha); !userLinksHypha.Exists {
|
2021-02-17 18:41:35 +00:00
|
|
|
util.SetDefaultHeaderLinks()
|
|
|
|
} else {
|
|
|
|
contents, err := ioutil.ReadFile(userLinksHypha.TextPath)
|
|
|
|
if err != nil || len(contents) == 0 {
|
|
|
|
util.SetDefaultHeaderLinks()
|
|
|
|
} else {
|
|
|
|
text := string(contents)
|
|
|
|
util.ParseHeaderLinks(text, markup.Rocketlink)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|