summaryrefslogtreecommitdiffhomepage
path: root/helpers/path_test.go
diff options
context:
space:
mode:
authorbep <[email protected]>2015-05-16 00:11:39 +0200
committerbep <[email protected]>2015-05-16 00:11:44 +0200
commitbeaa8b1bcabd4be25ac26bea39ab9f7290147e67 (patch)
tree76095c2b6ec9ddf22477c188c87f47e4c6cee8d6 /helpers/path_test.go
parente522e5f4154cb6a5d960aeb8920fa3e433641cf6 (diff)
downloadhugo-beaa8b1bcabd4be25ac26bea39ab9f7290147e67.tar.gz
hugo-beaa8b1bcabd4be25ac26bea39ab9f7290147e67.zip
Add support for URLs relative to context root
Setting `RelativeURLs` to `true` will make all relative URLs in the site *really* relative. And will do so with speed. So: In `/post/myblogpost.html`: `/mycss.css` becomes `../mycss.css` The same in `/index.html` will become: `./mycss.css` etc. Note that absolute URLs will not be touched (either external resources, or URLs constructed with `BaseURL`). The speediness is about the same as before: ``` benchmark old ns/op new ns/op delta BenchmarkAbsURL 17462 18164 +4.02% BenchmarkAbsURLSrcset 18842 19632 +4.19% BenchmarkXMLAbsURLSrcset 18643 19313 +3.59% BenchmarkXMLAbsURL 9283 9656 +4.02% benchmark old allocs new allocs delta BenchmarkAbsURL 24 28 +16.67% BenchmarkAbsURLSrcset 29 32 +10.34% BenchmarkXMLAbsURLSrcset 27 30 +11.11% BenchmarkXMLAbsURL 12 14 +16.67% benchmark old bytes new bytes delta BenchmarkAbsURL 3154 3404 +7.93% BenchmarkAbsURLSrcset 2376 2573 +8.29% BenchmarkXMLAbsURLSrcset 2569 2763 +7.55% BenchmarkXMLAbsURL 1888 1998 +5.83% ``` Fixes #1104 Fixes #622 Fixes #937 Fixes #157
Diffstat (limited to 'helpers/path_test.go')
-rw-r--r--helpers/path_test.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/helpers/path_test.go b/helpers/path_test.go
index a6da1a01a..364d0c39f 100644
--- a/helpers/path_test.go
+++ b/helpers/path_test.go
@@ -112,6 +112,45 @@ func TestMakePathRelative(t *testing.T) {
}
}
+func TestGetDottedRelativePath(t *testing.T) {
+ // on Windows this will receive both kinds, both country and western ...
+ for _, f := range []func(string) string{filepath.FromSlash, func(s string) string { return s }} {
+ doTestGetDottedRelativePath(f, t)
+ }
+
+}
+
+func doTestGetDottedRelativePath(urlFixer func(string) string, t *testing.T) {
+ type test struct {
+ input, expected string
+ }
+ data := []test{
+ {"", "./"},
+ {urlFixer("/"), "./"},
+ {urlFixer("post"), "../"},
+ {urlFixer("/post"), "../"},
+ {urlFixer("post/"), "../"},
+ {urlFixer("tags/foo.html"), "../"},
+ {urlFixer("/tags/foo.html"), "../"},
+ {urlFixer("/post/"), "../"},
+ {urlFixer("////post/////"), "../"},
+ {urlFixer("/foo/bar/index.html"), "../../"},
+ {urlFixer("/foo/bar/foo/"), "../../../"},
+ {urlFixer("/foo/bar/foo"), "../../../"},
+ {urlFixer("foo/bar/foo/"), "../../../"},
+ {urlFixer("foo/bar/foo/bar"), "../../../../"},
+ {"404.html", "./"},
+ {"404.xml", "./"},
+ {"/404.html", "./"},
+ }
+ for i, d := range data {
+ output := GetDottedRelativePath(d.input)
+ if d.expected != output {
+ t.Errorf("Test %d failed. Expected %q got %q", i, d.expected, output)
+ }
+ }
+}
+
func TestMakeTitle(t *testing.T) {
type test struct {
input, expected string