replace non-ascii characters in filename

This commit is contained in:
gutmet 2021-06-28 09:21:43 +02:00
parent 7c3c21d534
commit 8f552a2440

View File

@ -19,6 +19,7 @@ import (
"strings" "strings"
"text/template" "text/template"
"time" "time"
"unicode"
) )
var dir string 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 { func filename(s string) string {
return url.QueryEscape(s) return url.QueryEscape(convASCII(s))
} }
func filenameDate(date calendarMonth) string { func filenameDate(date calendarMonth) string {