Files
quyun/backend/pkg/utils/posts.go
2025-04-22 20:01:50 +08:00

46 lines
759 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package utils
import "strings"
// FormatTitle
// Format the title of a media file by replacing spaces with underscores and removing special characters
func FormatTitle(title string) string {
// remove file ext from title
if strings.Contains(title, ".") {
title = strings.Split(title, ".")[0]
}
// replace all spaces with underscores
replacements := []string{
" ", "",
"!", "",
"@", "",
"#", "",
"$", "",
"%", "",
"^", "",
"&", "",
"*", "",
"(", "",
")", "",
"[", "【",
"]", "】",
"{", "《",
"}", "》",
":", "",
";", "",
"'", "",
"\"", "",
"<", "",
">", "",
",", "",
".", "",
"?", "",
}
replacer := strings.NewReplacer(replacements...)
title = replacer.Replace(title)
return title
}