diff options
author | Noah Campbell <noahcampbell@gmail.com> | 2013-09-13 03:17:53 +0400 |
---|---|---|
committer | Noah Campbell <noahcampbell@gmail.com> | 2013-09-13 03:18:30 +0400 |
commit | 2f10da15707e1db0fab90524a247bc8a2d3ded90 (patch) | |
tree | 0023014b3e3ce84d541afd017e1a3b72a251e4f1 /target | |
parent | 74b55fc7c87f2887c42ce8626cb461fee5d7b907 (diff) |
Move alias rendering to target
Diffstat (limited to 'target')
-rw-r--r-- | target/alias_test.go | 31 | ||||
-rw-r--r-- | target/htmlredirect.go | 18 |
2 files changed, 49 insertions, 0 deletions
diff --git a/target/alias_test.go b/target/alias_test.go new file mode 100644 index 000000000..b25fe84a2 --- /dev/null +++ b/target/alias_test.go @@ -0,0 +1,31 @@ +package target + +import ( + "testing" +) + +func TestHTMLRedirectAlias(t *testing.T) { + var o Translator + o = new(HTMLRedirectAlias) + + tests := []struct { + value string + expected string + }{ + {"", ""}, + {"alias 1", "alias-1"}, + {"alias 2/", "alias-2/index.html"}, + {"alias 3.html", "alias-3.html"}, + } + + for _, test := range tests { + path, err := o.Translate(test.value) + if err != nil { + t.Fatalf("Translate returned an error: %s", err) + } + + if path != test.expected { + t.Errorf("Expected: %s, got: %s", test.expected, path) + } + } +} diff --git a/target/htmlredirect.go b/target/htmlredirect.go new file mode 100644 index 000000000..3305e2921 --- /dev/null +++ b/target/htmlredirect.go @@ -0,0 +1,18 @@ +package target + +import ( + helpers "github.com/spf13/hugo/template" + "path" + "strings" +) + +type HTMLRedirectAlias struct { + PublishDir string +} + +func (h *HTMLRedirectAlias) Translate(alias string) (aliasPath string, err error) { + if strings.HasSuffix(alias, "/") { + alias = alias + "index.html" + } + return path.Join(h.PublishDir, helpers.Urlize(alias)), nil +} |