mirror of
https://github.com/tiennm99/hugoDocs.git
synced 2026-10-19 08:15:16 +00:00
hugolib: Cache the value of Page's RelPermalink
This commit is contained in:
1 parent
7e0fa13faa
commit
fe9fd0acf4
1 file changed
+10
-3
+10
-3
@@ -190,6 +190,7 @@ type Page struct {
|
|||||||
|
|
||||||
URLPath
|
URLPath
|
||||||
permalink *url.URL
|
permalink *url.URL
|
||||||
|
relPermalink string
|
||||||
|
|
||||||
paginator *Pager
|
paginator *Pager
|
||||||
|
|
||||||
@@ -213,6 +214,7 @@ type pageInit struct {
|
|||||||
plainWordsInit sync.Once
|
plainWordsInit sync.Once
|
||||||
renderingConfigInit sync.Once
|
renderingConfigInit sync.Once
|
||||||
pageURLInit sync.Once
|
pageURLInit sync.Once
|
||||||
|
relPermalinkInit sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsNode returns whether this is an item of one of the list types in Hugo,
|
// IsNode returns whether this is an item of one of the list types in Hugo,
|
||||||
@@ -927,6 +929,7 @@ func (p *Page) URL() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) RelPermalink() string {
|
func (p *Page) RelPermalink() string {
|
||||||
|
p.relPermalinkInit.Do(func() {
|
||||||
link := p.getPermalink()
|
link := p.getPermalink()
|
||||||
|
|
||||||
if p.s.Info.canonifyURLs {
|
if p.s.Info.canonifyURLs {
|
||||||
@@ -934,7 +937,7 @@ func (p *Page) RelPermalink() string {
|
|||||||
// have to return the URL relative from baseURL
|
// have to return the URL relative from baseURL
|
||||||
relpath, err := helpers.GetRelativePath(link.String(), string(p.Site.BaseURL))
|
relpath, err := helpers.GetRelativePath(link.String(), string(p.Site.BaseURL))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
relpath = filepath.ToSlash(relpath)
|
relpath = filepath.ToSlash(relpath)
|
||||||
@@ -947,14 +950,18 @@ func (p *Page) RelPermalink() string {
|
|||||||
relpath = "/" + relpath
|
relpath = "/" + relpath
|
||||||
}
|
}
|
||||||
|
|
||||||
return relpath
|
p.relPermalink = relpath
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
link.Scheme = ""
|
link.Scheme = ""
|
||||||
link.Host = ""
|
link.Host = ""
|
||||||
link.User = nil
|
link.User = nil
|
||||||
link.Opaque = ""
|
link.Opaque = ""
|
||||||
return link.String()
|
p.relPermalink = link.String()
|
||||||
|
})
|
||||||
|
|
||||||
|
return p.relPermalink
|
||||||
}
|
}
|
||||||
|
|
||||||
var ErrHasDraftAndPublished = errors.New("both draft and published parameters were found in page's frontmatter")
|
var ErrHasDraftAndPublished = errors.New("both draft and published parameters were found in page's frontmatter")
|
||||||
|
|||||||
Reference in new issue
Block a user