summaryrefslogtreecommitdiffstats
path: root/hugolib/site.go
diff options
context:
space:
mode:
authorVas Sudanagunta <vas@commonkarma.org>2018-05-29 21:35:27 -0400
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-07-18 00:07:20 +0200
commitb93417aa1d3d38a9e56bad25937e0e638a113faf (patch)
tree86d0ab6972b845b81204516c2716c597e851c03c /hugolib/site.go
parentfd1f4a7860c4b989865b47c727239cf924a52fa4 (diff)
Unify page lookups
This commit unifies the core internal page index for all page kinds. This enables the `ref` and `relref` shortcodes to support all pages kinds, and adds a new page-relative `.GetPage` method with simplified signature. See #4147 See #4727 See #4728 See #4728 See #4726 See #4652
Diffstat (limited to 'hugolib/site.go')
-rw-r--r--hugolib/site.go25
1 files changed, 18 insertions, 7 deletions
diff --git a/hugolib/site.go b/hugolib/site.go
index 5e300393b..e04983695 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -21,6 +21,7 @@ import (
"mime"
"net/url"
"os"
+ "path"
"path/filepath"
"sort"
"strconv"
@@ -492,7 +493,6 @@ func (s *SiteInfo) refLink(ref string, page *Page, relative bool, outputFormat s
var err error
ref = filepath.ToSlash(ref)
- ref = strings.TrimPrefix(ref, "/")
refURL, err = url.Parse(ref)
@@ -504,7 +504,11 @@ func (s *SiteInfo) refLink(ref string, page *Page, relative bool, outputFormat s
var link string
if refURL.Path != "" {
- target := s.getPage(KindPage, refURL.Path)
+ target, err := s.getPage(page, refURL.Path)
+
+ if err != nil {
+ return "", err
+ }
if target == nil {
return "", fmt.Errorf("No page found with path or logical name \"%s\".\n", refURL.Path)
@@ -1598,13 +1602,20 @@ func (s *Site) appendThemeTemplates(in []string) []string {
}
-// GetPage looks up a page of a given type in the path given.
+// 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 the
-// first page found if the key is ambigous.
-func (s *SiteInfo) GetPage(typ string, path ...string) (*Page, error) {
- return s.getPage(typ, path...), nil
+// 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) {
+ var key string
+ if len(ref) == 1 {
+ key = filepath.ToSlash(ref[0])
+ } else {
+ key = path.Join(ref...)
+ }
+
+ return s.getPage(nil, key)
}
func (s *Site) permalinkForOutputFormat(link string, f output.Format) (string, error) {