package hyphae import ( "fmt" "io/ioutil" "os" "path/filepath" "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. func (h *Hypha) FetchTextPart() (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 } // binaryHtmlBlock creates an html block for binary part of the hypha. func (h *Hypha) BinaryHtmlBlock() string { switch filepath.Ext(h.BinaryPath) { case ".jpg", ".gif", ".png", ".webp", ".svg", ".ico": return fmt.Sprintf(`
`, h.Name) case ".ogg", ".webm", ".mp4": return fmt.Sprintf(`
`, h.Name) case ".mp3": return fmt.Sprintf(`
`, h.Name) default: return fmt.Sprintf(` `, h.Name) } } func SetHeaderLinks() { if userLinksHypha := ByName(util.HeaderLinksHypha); !userLinksHypha.Exists { 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) } } }