1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 11:46:16 +00:00
mycorrhiza/shroom/view.go
Timur Ismagilov 4fcf5abb37 Migrate to mycomarkup v0.3.0
Break a lot of things as well:
* OpenGraph is temporarily removed
* Link coloring is broken
* RocketLink display text is lost for some reason
* List nesting is lost?

Some things got fixed though:
* External link icons are back

And new features:
* Multiline list entries (tasty)
2021-05-24 14:33:57 +05:00

38 lines
848 B
Go

package shroom
import (
"io/ioutil"
"os"
"github.com/bouncepaw/mycorrhiza/cfg"
"github.com/bouncepaw/mycorrhiza/hyphae"
)
// 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)
}
}
}