mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-19 04:14:16 +00:00
hugolib: Create the permalink once only
This commit is contained in:
parent
046320d3f4
commit
20d82a7a1b
1 changed files with 23 additions and 11 deletions
|
@ -192,6 +192,7 @@ type Page struct {
|
||||||
RSSLink template.HTML
|
RSSLink template.HTML
|
||||||
|
|
||||||
URLPath
|
URLPath
|
||||||
|
permalink *url.URL
|
||||||
|
|
||||||
paginator *Pager
|
paginator *Pager
|
||||||
|
|
||||||
|
@ -211,6 +212,7 @@ type pageInit struct {
|
||||||
plainInit sync.Once
|
plainInit sync.Once
|
||||||
plainWordsInit sync.Once
|
plainWordsInit sync.Once
|
||||||
renderingConfigInit sync.Once
|
renderingConfigInit sync.Once
|
||||||
|
pageURLInit 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,
|
||||||
|
@ -724,7 +726,25 @@ func (p *Page) analyzePage() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) permalink() (*url.URL, error) {
|
func (p *Page) getPermalink() *url.URL {
|
||||||
|
p.pageURLInit.Do(func() {
|
||||||
|
u, err := p.createPermalink()
|
||||||
|
if err != nil {
|
||||||
|
jww.ERROR.Printf("Failed to create permalink for page %q: %s", p.FullFilePath(), err)
|
||||||
|
p.permalink = new(url.URL)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
p.permalink = u
|
||||||
|
})
|
||||||
|
|
||||||
|
// The link may be modified by the receiver, so create a copy.
|
||||||
|
l := *p.permalink
|
||||||
|
|
||||||
|
return &l
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Page) createPermalink() (*url.URL, error) {
|
||||||
// TODO(bep) this should probably be set once during build. Maybe.
|
// TODO(bep) this should probably be set once during build. Maybe.
|
||||||
// And simplified.
|
// And simplified.
|
||||||
baseURL := string(p.Site.BaseURL)
|
baseURL := string(p.Site.BaseURL)
|
||||||
|
@ -842,12 +862,7 @@ func (p *Page) IsExpired() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) Permalink() string {
|
func (p *Page) Permalink() string {
|
||||||
link, err := p.permalink()
|
return p.getPermalink().String()
|
||||||
if err != nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
return link.String()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) URL() string {
|
func (p *Page) URL() string {
|
||||||
|
@ -862,10 +877,7 @@ func (p *Page) URL() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) RelPermalink() string {
|
func (p *Page) RelPermalink() string {
|
||||||
link, err := p.permalink()
|
link := p.getPermalink()
|
||||||
if err != nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
if viper.GetBool("canonifyURLs") {
|
if viper.GetBool("canonifyURLs") {
|
||||||
// replacements for relpermalink with baseURL on the form http://myhost.com/sub/ will fail later on
|
// replacements for relpermalink with baseURL on the form http://myhost.com/sub/ will fail later on
|
||||||
|
|
Loading…
Add table
Reference in a new issue