import (
"net/url"
"path"
+
+ "github.com/PuerkitoBio/purell"
)
+func SanitizeUrl(in string) string {
+ url, err := purell.NormalizeURLString(in, purell.FlagsUsuallySafeGreedy|purell.FlagRemoveDuplicateSlashes|purell.FlagRemoveUnnecessaryHostDots|purell.FlagRemoveEmptyPortSeparator)
+ if err != nil {
+ return in
+ }
+ return url
+}
+
// Similar to MakePath, but with Unicode handling
// Example:
// uri: Vim (text editor)
}
func UrlPrep(ugly bool, in string) string {
+ in = SanitizeUrl(in)
if ugly {
return Uglify(in)
} else {
import (
"errors"
- "github.com/eknkc/amber"
- "github.com/spf13/hugo/helpers"
"html"
"html/template"
"io"
"reflect"
"strconv"
"strings"
+
+ "github.com/eknkc/amber"
+ "github.com/spf13/hugo/helpers"
)
func Gt(a interface{}, b interface{}) bool {
}
funcMap := template.FuncMap{
- "urlize": helpers.Urlize,
- "gt": Gt,
- "isset": IsSet,
- "echoParam": ReturnWhenSet,
- "safeHtml": SafeHtml,
- "first": First,
- "highlight": Highlight,
- "add": func(a, b int) int { return a + b },
- "sub": func(a, b int) int { return a - b },
- "div": func(a, b int) int { return a / b },
- "mod": func(a, b int) int { return a % b },
- "mul": func(a, b int) int { return a * b },
- "modBool": func(a, b int) bool { return a%b == 0 },
- "lower": func(a string) string { return strings.ToLower(a) },
- "upper": func(a string) string { return strings.ToUpper(a) },
- "title": func(a string) string { return strings.Title(a) },
+ "urlize": helpers.Urlize,
+ "sanitizeurl": helpers.SanitizeUrl,
+ "gt": Gt,
+ "isset": IsSet,
+ "echoParam": ReturnWhenSet,
+ "safeHtml": SafeHtml,
+ "first": First,
+ "highlight": Highlight,
+ "add": func(a, b int) int { return a + b },
+ "sub": func(a, b int) int { return a - b },
+ "div": func(a, b int) int { return a / b },
+ "mod": func(a, b int) int { return a % b },
+ "mul": func(a, b int) int { return a * b },
+ "modBool": func(a, b int) bool { return a%b == 0 },
+ "lower": func(a string) string { return strings.ToLower(a) },
+ "upper": func(a string) string { return strings.ToUpper(a) },
+ "title": func(a string) string { return strings.Title(a) },
}
templates.Funcs(funcMap)