mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-13 05:50:27 +00:00
da6ea25bb6
The old module had been moved to the library, but I changed it a little, so now both projects are broken. I sure do love programming.
40 lines
910 B
Go
40 lines
910 B
Go
package shroom
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
|
|
|
"github.com/bouncepaw/mycomarkup/blocks"
|
|
)
|
|
|
|
// 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, blocks.Rocketlink)
|
|
}
|
|
}
|
|
}
|