Post-Migrator/services/slowtwitch/url-converter.go

37 lines
962 B
Go
Raw Normal View History

package slowtwitch
2024-05-20 01:35:53 +00:00
import (
"strconv"
"strings"
)
func ConvertUrlToCategoryFormat(oldUrl string) string {
2024-05-17 18:49:55 +00:00
output := convert(oldUrl)
return "/" + output + "/index.html"
}
2024-05-17 18:49:55 +00:00
func ConvertPostTitleToPath(title string, id int) string {
output := convert(title)
2024-05-20 01:35:53 +00:00
return output + "_" + strconv.Itoa(id) + ".html"
2024-05-17 18:49:55 +00:00
}
func GetURL(path string) string {
2024-05-17 18:49:55 +00:00
return "https://www.slowtwitch.com" + path
}
func convert(path string) string {
output := strings.ReplaceAll(path, " ", "_")
output = strings.ReplaceAll(output, "$", "_")
output = strings.ReplaceAll(output, "(", "_")
output = strings.ReplaceAll(output, ")", "_")
2024-05-20 01:35:53 +00:00
output = strings.ReplaceAll(output, "?", "")
output = strings.ReplaceAll(output, ",", "")
output = strings.ReplaceAll(output, "%", "%25")
2024-06-03 22:28:17 +00:00
output = strings.ReplaceAll(output, "_&", "")
output = strings.ReplaceAll(output, "&", "")
output = strings.ReplaceAll(output, "#", "")
output = strings.ReplaceAll(output, ";", "")
2024-05-17 18:49:55 +00:00
return output
}