Improvements

This commit is contained in:
Henrique Dias committed 2016-10-18 21:49:46 +01:00
1 parent f2fbe92591
commit fe7579966d
7 files changed
+90 -96

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
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":
return frontmatter
}
return frontmatter
}