diff --git a/finstr.go b/finstr.go index 3950d3c..92c777d 100644 --- a/finstr.go +++ b/finstr.go @@ -19,6 +19,7 @@ import ( "strings" "text/template" "time" + "unicode" ) var dir string @@ -130,8 +131,26 @@ func byModified(p []photo) func(int, int) bool { /*-------------------------*/ +func isASCII(r rune) bool { + return r <= 127 +} + +func convASCII(s string) string { + out := []rune(s) + for i, c := range out { + if (isASCII(c) && (unicode.IsLetter(c) || unicode.IsDigit(c))) || c == '.' { + // keep unchanged + } else if unicode.IsSpace(c) || unicode.IsPunct(c) { + out[i] = '-' + } else { + out[i] = 'x' + } + } + return string(out) +} + func filename(s string) string { - return url.QueryEscape(s) + return url.QueryEscape(convASCII(s)) } func filenameDate(date calendarMonth) string {