filebrowser/frontmatter/runes.go

25 lines
632 B
Go
Raw Normal View History

2016-10-18 20:49:46 +00:00
package frontmatter
import "strings"
// HasRune checks if the file has the frontmatter rune
func HasRune(file []byte) bool {
return strings.HasPrefix(string(file), "---") ||
strings.HasPrefix(string(file), "+++") ||
strings.HasPrefix(string(file), "{")
}
// AppendRune appends the frontmatter rune to a file
func AppendRune(frontmatter []byte, language string) []byte {
switch language {
case "yaml":
return []byte("---\n" + string(frontmatter) + "\n---")
case "toml":
return []byte("+++\n" + string(frontmatter) + "\n+++")
case "json":
2017-01-04 18:17:47 +00:00
return []byte("{\n" + string(frontmatter) + "\n}")
2016-10-18 20:49:46 +00:00
}
return frontmatter
}