adding helper to create absolute url
authorspf13 <steve.francia@gmail.com>
Wed, 10 Jul 2013 21:57:28 +0000 (17:57 -0400)
committerspf13 <steve.francia@gmail.com>
Wed, 10 Jul 2013 21:57:28 +0000 (17:57 -0400)
hugolib/helpers.go

index 4ebeea9980464519e4ebfbb975e1685e13e92221..ad3c20277dade8dd0483f95ec24a4a2d691b72a3 100644 (file)
@@ -22,6 +22,7 @@ import (
        "regexp"
        "strconv"
        "strings"
+       "html/template"
        "time"
 )
 
@@ -147,6 +148,13 @@ func Urlize(url string) string {
        return Sanitize(strings.ToLower(strings.Replace(strings.TrimSpace(url), " ", "-", -1)))
 }
 
+func AbsUrl(url string, base string) template.HTML {
+       if strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") {
+               return template.HTML(url)
+       }
+       return template.HTML(MakePermalink(base, url))
+}
+
 func Gt(a interface{}, b interface{}) bool {
        var left, right int64
        av := reflect.ValueOf(a)