mirror of
https://github.com/gohugoio/hugo.git
synced 2024-05-11 05:54:58 +00:00
Add /index.html to unadorned alias paths
Bring code to be better in line with documentation.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package target
|
||||
|
||||
import (
|
||||
helpers "github.com/spf13/hugo/template"
|
||||
"path"
|
||||
"bytes"
|
||||
"strings"
|
||||
helpers "github.com/spf13/hugo/template"
|
||||
"html/template"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user