Former-commit-id: e4a5da856ccf794aa1517ca44e8ee47d83ef0f2d
This commit is contained in:
Henrique Dias
2017-01-18 18:20:56 +00:00
parent b29d284591
commit 3b9c687af7
7 changed files with 69 additions and 31 deletions

View File

@@ -1,6 +1,9 @@
package frontmatter
import "strings"
import (
"bytes"
"strings"
)
// HasRune checks if the file has the frontmatter rune
func HasRune(file []byte) bool {
@@ -10,15 +13,43 @@ func HasRune(file []byte) bool {
}
// AppendRune appends the frontmatter rune to a file
func AppendRune(frontmatter []byte, language string) []byte {
switch language {
case "yaml":
func AppendRune(frontmatter []byte, mark rune) []byte {
frontmatter = bytes.TrimSpace(frontmatter)
switch mark {
case '-':
return []byte("---\n" + string(frontmatter) + "\n---")
case "toml":
case '+':
return []byte("+++\n" + string(frontmatter) + "\n+++")
case "json":
case '{':
return []byte("{\n" + string(frontmatter) + "\n}")
}
return frontmatter
}
func RuneToStringFormat(mark rune) string {
switch mark {
case '-':
return "yaml"
case '+':
return "toml"
case '{':
return "json"
default:
return ""
}
}
func StringFormatToRune(format string) rune {
switch format {
case "yaml":
return '-'
case "toml":
return '+'
case "json":
return '{'
default:
return '0'
}
}