mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
3b9c687af7
Former-commit-id: e4a5da856c
56 lines
1013 B
Go
56 lines
1013 B
Go
package frontmatter
|
|
|
|
import (
|
|
"bytes"
|
|
"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, mark rune) []byte {
|
|
frontmatter = bytes.TrimSpace(frontmatter)
|
|
|
|
switch mark {
|
|
case '-':
|
|
return []byte("---\n" + string(frontmatter) + "\n---")
|
|
case '+':
|
|
return []byte("+++\n" + string(frontmatter) + "\n+++")
|
|
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'
|
|
}
|
|
}
|