mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-05-09 03:32:56 +00:00

Former-commit-id: bd8ab54a13b08f223cc00a5372dc885c5b7b49e6 [formerly 169211b32940ffa9a157bf140579e1946b8df75d] [formerly 1795b434a35c2f9dc3c6940b7555542f62f3d74d [formerly 1ae2afb9985b82c7c101395c8a65fd122200c808]] Former-commit-id: 1ed1a0402184384c37b80d51ef1460d036d5201e [formerly e068d59a1b531635e6ccad4d2203c1ef9eab7c86] Former-commit-id: 391cbcefcd6b9f98b054bc02aec5cf808ccd199f
29 lines
593 B
Go
29 lines
593 B
Go
package frontmatter
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// HasRune checks if the file has the frontmatter rune
|
|
func HasRune(file string) bool {
|
|
return strings.HasPrefix(file, "---") ||
|
|
strings.HasPrefix(file, "+++") ||
|
|
strings.HasPrefix(file, "{")
|
|
}
|
|
|
|
// AppendRune appends the frontmatter rune to a file
|
|
func AppendRune(frontmatter string, mark rune) string {
|
|
frontmatter = strings.TrimSpace(frontmatter)
|
|
|
|
switch mark {
|
|
case '-':
|
|
return "---\n" + frontmatter + "\n---"
|
|
case '+':
|
|
return "+++\n" + frontmatter + "\n+++"
|
|
case '{':
|
|
return "{\n" + frontmatter + "\n}"
|
|
}
|
|
|
|
return frontmatter
|
|
}
|