summaryrefslogtreecommitdiffstats
path: root/hugolib/site.go
diff options
context:
space:
mode:
Diffstat (limited to 'hugolib/site.go')
-rw-r--r--hugolib/site.go47
1 files changed, 36 insertions, 11 deletions
diff --git a/hugolib/site.go b/hugolib/site.go
index e04983695..865217176 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -21,7 +21,6 @@ import (
"mime"
"net/url"
"os"
- "path"
"path/filepath"
"sort"
"strconv"
@@ -504,7 +503,7 @@ func (s *SiteInfo) refLink(ref string, page *Page, relative bool, outputFormat s
var link string
if refURL.Path != "" {
- target, err := s.getPage(page, refURL.Path)
+ target, err := s.getPageNew(page, refURL.Path)
if err != nil {
return "", err
@@ -1603,19 +1602,45 @@ func (s *Site) appendThemeTemplates(in []string) []string {
}
// GetPage looks up a page of a given type for the given ref.
-// {{ with .Site.GetPage "section" "blog" }}{{ .Title }}{{ end }}
-//
-// This will return nil when no page could be found, and will return an
-// error if the key is ambiguous.
-func (s *SiteInfo) GetPage(typ string, ref ...string) (*Page, error) {
+// In Hugo <= 0.44 you had to add Page Kind (section, home) etc. as the first
+// argument and then either a unix styled path (with or without a leading slash))
+// or path elements separated.
+// When we now remove the Kind from this API, we need to make the transition as painless
+// as possible for existing sites. Most sites will use {{ .Site.GetPage "section" "my/section" }},
+// i.e. 2 arguments, so we test for that.
+func (s *SiteInfo) GetPage(ref ...string) (*Page, error) {
+ var refs []string
+ for _, r := range ref {
+ // A common construct in the wild is
+ // .Site.GetPage "home" "" or
+ // .Site.GetPage "home" "/"
+ if r != "" && r != "/" {
+ refs = append(refs, r)
+ }
+ }
+
var key string
- if len(ref) == 1 {
- key = filepath.ToSlash(ref[0])
+
+ if len(refs) > 2 {
+ // This was allowed in Hugo <= 0.44, but we cannot support this with the
+ // new API. This should be the most unusual case.
+ return nil, fmt.Errorf(`too many arguments to .Site.GetPage: %v. Use lookups on the form {{ .Site.GetPage "/posts/mypage-md" }}`, ref)
+ }
+
+ if len(refs) == 0 || refs[0] == KindHome {
+ key = "/"
+ } else if len(refs) == 1 {
+ key = refs[0]
} else {
- key = path.Join(ref...)
+ key = refs[1]
+ }
+
+ key = filepath.ToSlash(key)
+ if !strings.HasPrefix(key, "/") {
+ key = "/" + key
}
- return s.getPage(nil, key)
+ return s.getPageNew(nil, key)
}
func (s *Site) permalinkForOutputFormat(link string, f output.Format) (string, error) {