diff options
author | Noah Campbell <noahcampbell@gmail.com> | 2013-09-14 01:46:34 +0400 |
---|---|---|
committer | Noah Campbell <noahcampbell@gmail.com> | 2013-09-14 01:51:28 +0400 |
commit | d45fb72f675997d11406bce82919f1dc50414d68 (patch) | |
tree | 5530acc023ae7d39955142bdd8e7bbc084111d80 /target | |
parent | 803a0fce1ef3f2f42ed649a489ae381586445886 (diff) |
Add /index.html to unadorned alias paths
Bring code to be better in line with documentation.
Diffstat (limited to 'target')
-rw-r--r-- | target/alias_test.go | 6 | ||||
-rw-r--r-- | target/htmlredirect.go | 14 |
2 files changed, 15 insertions, 5 deletions
diff --git a/target/alias_test.go b/target/alias_test.go index b25fe84a2..7f5db79af 100644 --- a/target/alias_test.go +++ b/target/alias_test.go @@ -13,9 +13,13 @@ func TestHTMLRedirectAlias(t *testing.T) { expected string }{ {"", ""}, - {"alias 1", "alias-1"}, + {"s", "s/index.html"}, + {"/", "/index.html"}, + {"alias 1", "alias-1/index.html"}, {"alias 2/", "alias-2/index.html"}, {"alias 3.html", "alias-3.html"}, + {"alias4.html", "alias4.html"}, + {"/alias 5.html", "/alias-5.html"}, } for _, test := range tests { diff --git a/target/htmlredirect.go b/target/htmlredirect.go index 398d3fefa..a2695c6d9 100644 --- a/target/htmlredirect.go +++ b/target/htmlredirect.go @@ -1,15 +1,15 @@ package target import ( + "bytes" helpers "github.com/spf13/hugo/template" + "html/template" "path" - "bytes" "strings" - "html/template" ) const ALIAS = "<!DOCTYPE html><html><head><link rel=\"canonical\" href=\"{{ .Permalink }}\"/><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" /><meta http-equiv=\"refresh\" content=\"0;url={{ .Permalink }}\" /></head></html>" -const ALIAS_XHTML = "<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><link rel=\"canonical\" href=\"{{ .Permalink }}\"/><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" /><meta http-equiv=\"refresh\" content=\"0;url={{ .Permalink }}\" /></head></html>" +const ALIAS_XHTML = "<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><link rel=\"canonical\" href=\"{{ .Permalink }}\"/><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" /><meta http-equiv=\"refresh\" content=\"0;url={{ .Permalink }}\" /></head></html>" var DefaultAliasTemplates *template.Template @@ -26,12 +26,18 @@ type AliasPublisher interface { type HTMLRedirectAlias struct { PublishDir string - Templates *template.Template + Templates *template.Template } func (h *HTMLRedirectAlias) Translate(alias string) (aliasPath string, err error) { + if len(alias) <= 0 { + return + } + if strings.HasSuffix(alias, "/") { alias = alias + "index.html" + } else if !strings.HasSuffix(alias, ".html") { + alias = alias + "/index.html" } return path.Join(h.PublishDir, helpers.Urlize(alias)), nil } |