1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-12-02 21:57:47 +01:00
gojekyll/helpers.go
2017-06-16 15:47:41 -04:00

33 lines
701 B
Go

package main
import (
"regexp"
)
var nonAlphanumericSequenceMatcher = regexp.MustCompile(`[^[:alnum:]]+`)
// Slugify replaces each sequence of non-alphanumerics by a single hyphen
func Slugify(s string) string {
return nonAlphanumericSequenceMatcher.ReplaceAllString(s, "-")
}
// LeftPad left-pads s with spaces to n wide. It's an alternative to http://left-pad.io.
func LeftPad(s string, n int) string {
if n <= len(s) {
return s
}
ws := make([]byte, n-len(s))
for i := range ws {
ws[i] = ' '
}
return string(ws) + s
}
func stringArrayToMap(strings []string) map[string]bool {
stringMap := map[string]bool{}
for _, s := range strings {
stringMap[s] = true
}
return stringMap
}