1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-12-03 00:47:47 +01:00
gojekyll/helpers.go

33 lines
701 B
Go
Raw Normal View History

package main
import (
2017-06-15 16:17:21 +02:00
"regexp"
)
2017-06-15 16:17:21 +02:00
var nonAlphanumericSequenceMatcher = regexp.MustCompile(`[^[:alnum:]]+`)
2017-06-16 01:49:04 +02:00
// Slugify replaces each sequence of non-alphanumerics by a single hyphen
func Slugify(s string) string {
2017-06-15 15:07:06 +02:00
return nonAlphanumericSequenceMatcher.ReplaceAllString(s, "-")
}
2017-06-15 13:19:49 +02:00
// LeftPad left-pads s with spaces to n wide. It's an alternative to http://left-pad.io.
2017-06-13 23:19:05 +02:00
func LeftPad(s string, n int) string {
2017-06-11 22:00:03 +02:00
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
}