Former-commit-id: e4a5da856ccf794aa1517ca44e8ee47d83ef0f2d
This commit is contained in:
@@ -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'
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user