mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
d9d6a2bf44
Former-commit-id: b701d9f094
25 lines
632 B
Go
25 lines
632 B
Go
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 []byte("{\n" + string(frontmatter) + "\n}")
|
|
}
|
|
|
|
return frontmatter
|
|
}
|