summaryrefslogtreecommitdiffstats
path: root/transform/absurl.go
diff options
context:
space:
mode:
authorNoah Campbell <noahcampbell@gmail.com>2013-11-05 22:28:06 +0000
committerNoah Campbell <noahcampbell@gmail.com>2013-11-05 22:28:06 +0000
commit86233c00a0a04e8f0130a5970de8d40e6738ef74 (patch)
tree772e16697927e7bc564e640f6524781699437f02 /transform/absurl.go
parent1cebce12ad2335e1140646763dd56009c57d6495 (diff)
Remove the hugo-nav function
Remove the hugo-nav since it relied on a slow library. The current build reimplements the absurl functionality based on string replace. Discovered that my prior implementation missed the requirement for making absolute paths (/path) absolute with the host, whereas a relative path is left untouched. Updated the test cases to support this if this is reimplemented.
Diffstat (limited to 'transform/absurl.go')
-rw-r--r--transform/absurl.go19
1 files changed, 15 insertions, 4 deletions
diff --git a/transform/absurl.go b/transform/absurl.go
index f66edab9d..5967e597e 100644
--- a/transform/absurl.go
+++ b/transform/absurl.go
@@ -3,18 +3,29 @@ package transform
import (
htmltran "code.google.com/p/go-html-transform/html/transform"
"net/url"
+ "bytes"
)
-func AbsURL(absURL string) (trs []*htmltran.Transform, err error) {
+func AbsURL(absURL string) (trs []link, err error) {
var baseURL *url.URL
if baseURL, err = url.Parse(absURL); err != nil {
return
}
- if trs, err = absUrlify(baseURL, elattr{"a", "href"}, elattr{"script", "src"}); err != nil {
- return
- }
+ var (
+ srcdq = []byte(" src=\""+baseURL.String()+"/")
+ hrefdq = []byte(" href=\""+baseURL.String()+"/")
+ srcsq = []byte(" src='"+baseURL.String()+"/")
+ hrefsq = []byte(" href='"+baseURL.String()+"/")
+ )
+ trs = append(trs, func(content []byte) []byte {
+ content = bytes.Replace(content, []byte(" src=\"/"), srcdq, -1)
+ content = bytes.Replace(content, []byte(" src='/"), srcsq, -1)
+ content = bytes.Replace(content, []byte(" href=\"/"), hrefdq, -1)
+ content = bytes.Replace(content, []byte(" href='/"), hrefsq, -1)
+ return content
+ })
return
}