Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/target
diff options
context:
space:
mode:
authorNoah Campbell <noahcampbell@gmail.com>2013-09-13 03:17:53 +0400
committerNoah Campbell <noahcampbell@gmail.com>2013-09-13 03:18:30 +0400
commit2f10da15707e1db0fab90524a247bc8a2d3ded90 (patch)
tree0023014b3e3ce84d541afd017e1a3b72a251e4f1 /target
parent74b55fc7c87f2887c42ce8626cb461fee5d7b907 (diff)
Move alias rendering to target
Diffstat (limited to 'target')
-rw-r--r--target/alias_test.go31
-rw-r--r--target/htmlredirect.go18
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
+}