mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Add /index.html to unadorned alias paths
Bring code to be better in line with documentation.
This commit is contained in:
parent
803a0fce1e
commit
d45fb72f67
5 changed files with 37 additions and 25 deletions
|
@ -34,17 +34,17 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Page struct {
|
type Page struct {
|
||||||
Status string
|
Status string
|
||||||
Images []string
|
Images []string
|
||||||
Content template.HTML
|
Content template.HTML
|
||||||
Summary template.HTML
|
Summary template.HTML
|
||||||
RawMarkdown string // TODO should be []byte
|
RawMarkdown string // TODO should be []byte
|
||||||
Params map[string]interface{}
|
Params map[string]interface{}
|
||||||
contentType string
|
contentType string
|
||||||
Draft bool
|
Draft bool
|
||||||
Aliases []string
|
Aliases []string
|
||||||
Tmpl bundle.Template
|
Tmpl bundle.Template
|
||||||
Markup string
|
Markup string
|
||||||
PageMeta
|
PageMeta
|
||||||
File
|
File
|
||||||
Position
|
Position
|
||||||
|
|
|
@ -145,7 +145,9 @@ func (s *Site) Process() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) Render() (err error) {
|
func (s *Site) Render() (err error) {
|
||||||
s.RenderAliases()
|
if err = s.RenderAliases(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
s.timerStep("render and write aliases")
|
s.timerStep("render and write aliases")
|
||||||
s.ProcessShortcodes()
|
s.ProcessShortcodes()
|
||||||
s.timerStep("render shortcodes")
|
s.timerStep("render shortcodes")
|
||||||
|
@ -161,7 +163,7 @@ func (s *Site) Render() (err error) {
|
||||||
if err = s.RenderPages(); err != nil {
|
if err = s.RenderPages(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.timerStep("render pages")
|
s.timerStep("render and write pages")
|
||||||
if err = s.RenderHomePage(); err != nil {
|
if err = s.RenderHomePage(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,13 @@ package hugolib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"github.com/spf13/hugo/target"
|
||||||
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
"html/template"
|
|
||||||
"github.com/spf13/hugo/target"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const SLUG_DOC_1 = "---\ntitle: slug doc 1\nslug: slug-doc-1\naliases:\n - sd1/foo/\n - sd2\n - sd3/\n - sd4.php\n---\nslug doc 1 content"
|
const SLUG_DOC_1 = "---\ntitle: slug doc 1\nslug: slug-doc-1\naliases:\n - sd1/foo/\n - sd2\n - sd3/\n - sd4.html\n---\nslug doc 1 content"
|
||||||
|
|
||||||
//const SLUG_DOC_1 = "---\ntitle: slug doc 1\nslug: slug-doc-1\n---\nslug doc 1 content"
|
//const SLUG_DOC_1 = "---\ntitle: slug doc 1\nslug: slug-doc-1\n---\nslug doc 1 content"
|
||||||
const SLUG_DOC_2 = "---\ntitle: slug doc 2\nslug: slug-doc-2\n---\nslug doc 2 content"
|
const SLUG_DOC_2 = "---\ntitle: slug doc 2\nslug: slug-doc-2\n---\nslug doc 2 content"
|
||||||
|
@ -68,7 +68,7 @@ func TestPageCount(t *testing.T) {
|
||||||
alias := &InMemoryAliasTarget{files: files}
|
alias := &InMemoryAliasTarget{files: files}
|
||||||
s := &Site{
|
s := &Site{
|
||||||
Target: target,
|
Target: target,
|
||||||
Alias: alias,
|
Alias: alias,
|
||||||
Config: Config{UglyUrls: false},
|
Config: Config{UglyUrls: false},
|
||||||
Source: &inMemorySource{urlFakeSource},
|
Source: &inMemorySource{urlFakeSource},
|
||||||
}
|
}
|
||||||
|
@ -102,9 +102,9 @@ func TestPageCount(t *testing.T) {
|
||||||
|
|
||||||
for _, s := range []string{
|
for _, s := range []string{
|
||||||
"sd1/foo/index.html",
|
"sd1/foo/index.html",
|
||||||
"sd2",
|
"sd2/index.html",
|
||||||
"sd3/index.html",
|
"sd3/index.html",
|
||||||
"sd4.php",
|
"sd4.html",
|
||||||
} {
|
} {
|
||||||
if _, ok := target.files[s]; !ok {
|
if _, ok := target.files[s]; !ok {
|
||||||
t.Errorf("No alias rendered: %s", s)
|
t.Errorf("No alias rendered: %s", s)
|
||||||
|
|
|
@ -13,9 +13,13 @@ func TestHTMLRedirectAlias(t *testing.T) {
|
||||||
expected string
|
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 2/", "alias-2/index.html"},
|
||||||
{"alias 3.html", "alias-3.html"},
|
{"alias 3.html", "alias-3.html"},
|
||||||
|
{"alias4.html", "alias4.html"},
|
||||||
|
{"/alias 5.html", "/alias-5.html"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package target
|
package target
|
||||||
|
|
||||||
import (
|
import (
|
||||||
helpers "github.com/spf13/hugo/template"
|
|
||||||
"path"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"strings"
|
helpers "github.com/spf13/hugo/template"
|
||||||
"html/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 = "<!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
|
var DefaultAliasTemplates *template.Template
|
||||||
|
|
||||||
|
@ -26,12 +26,18 @@ type AliasPublisher interface {
|
||||||
|
|
||||||
type HTMLRedirectAlias struct {
|
type HTMLRedirectAlias struct {
|
||||||
PublishDir string
|
PublishDir string
|
||||||
Templates *template.Template
|
Templates *template.Template
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HTMLRedirectAlias) Translate(alias string) (aliasPath string, err error) {
|
func (h *HTMLRedirectAlias) Translate(alias string) (aliasPath string, err error) {
|
||||||
|
if len(alias) <= 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if strings.HasSuffix(alias, "/") {
|
if strings.HasSuffix(alias, "/") {
|
||||||
alias = alias + "index.html"
|
alias = alias + "index.html"
|
||||||
|
} else if !strings.HasSuffix(alias, ".html") {
|
||||||
|
alias = alias + "/index.html"
|
||||||
}
|
}
|
||||||
return path.Join(h.PublishDir, helpers.Urlize(alias)), nil
|
return path.Join(h.PublishDir, helpers.Urlize(alias)), nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue