Skip to content

Commit

Permalink
Finally remove deprecated Page methods
Browse files Browse the repository at this point in the history
They have been deprecated for a very long time, first with a warning, then with an ERROR. Now they are removed.

Closes #4117
  • Loading branch information
bep committed Feb 14, 2022
1 parent c707b71 commit 9563c7d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 112 deletions.
1 change: 0 additions & 1 deletion hugolib/page__common.go
Expand Up @@ -78,7 +78,6 @@ type pageCommon struct {
page.RefProvider
page.ShortcodeInfoProvider
page.SitesProvider
page.DeprecatedWarningPageMethods
page.TranslationsProvider
page.TreeProvider
resource.LanguageProvider
Expand Down
10 changes: 0 additions & 10 deletions hugolib/page__new.go
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/gohugoio/hugo/common/hugo"

"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/source"

"github.com/gohugoio/hugo/output"

Expand Down Expand Up @@ -65,15 +64,6 @@ func newPageBase(metaProvider *pageMeta) (*pageState, error) {

siteAdapter := pageSiteAdapter{s: s, p: ps}

deprecatedWarningPage := struct {
source.FileWithoutOverlap
page.DeprecatedWarningPageMethods1
}{
FileWithoutOverlap: metaProvider.File(),
DeprecatedWarningPageMethods1: &pageDeprecatedWarning{p: ps},
}

ps.DeprecatedWarningPageMethods = page.NewDeprecatedWarningPage(deprecatedWarningPage)
ps.pageMenus = &pageMenus{p: ps}
ps.PageMenusProvider = ps.pageMenus
ps.GetPageProvider = siteAdapter
Expand Down
14 changes: 1 addition & 13 deletions resources/page/page.go
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/tpl"

"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/compare"
"github.com/gohugoio/hugo/hugofs/files"
Expand Down Expand Up @@ -379,18 +378,7 @@ type TreeProvider interface {
// DeprecatedWarningPageMethods lists deprecated Page methods that will trigger
// a WARNING if invoked.
// This was added in Hugo 0.55.
type DeprecatedWarningPageMethods interface {
source.FileWithoutOverlap
DeprecatedWarningPageMethods1
}

type DeprecatedWarningPageMethods1 interface {
IsDraft() bool
Hugo() hugo.Info
LanguagePrefix() string
GetParam(key string) interface{}
RSSLink() template.URL
URL() string
type DeprecatedWarningPageMethods interface { // This was emptied in Hugo 0.93.0.
}

// Move here to trigger ERROR instead of WARNING.
Expand Down
18 changes: 6 additions & 12 deletions resources/page/page_generate/generate_page_wrappers.go
Expand Up @@ -47,7 +47,6 @@ const header = `// Copyright 2019 The Hugo Authors. All rights reserved.
`

var (
fileInterfaceDeprecated = reflect.TypeOf((*source.FileWithoutOverlap)(nil)).Elem()
pageInterfaceDeprecated = reflect.TypeOf((*page.DeprecatedWarningPageMethods)(nil)).Elem()
pageInterface = reflect.TypeOf((*page.Page)(nil)).Elem()

Expand Down Expand Up @@ -155,23 +154,17 @@ func generateDeprecatedWrappers(c *codegen.Inspector) error {
}

deprecated := func(name string, tp reflect.Type) string {
var alternative string
if tp == fileInterfaceDeprecated {
alternative = "Use .File." + name
} else {
var found bool
alternative, found = reasons[name]
if !found {
panic(fmt.Sprintf("no deprecated reason found for %q", name))
}
alternative, found := reasons[name]
if !found {
panic(fmt.Sprintf("no deprecated reason found for %q", name))
}

return fmt.Sprintf("helpers.Deprecated(%q, %q, true)", "Page."+name, alternative)
}

var buff bytes.Buffer

methods := c.MethodsFromTypes([]reflect.Type{fileInterfaceDeprecated, pageInterfaceDeprecated}, nil)
methods := c.MethodsFromTypes([]reflect.Type{pageInterfaceDeprecated}, nil)

for _, m := range methods {
fmt.Fprint(&buff, m.Declaration("*pageDeprecated"))
Expand All @@ -181,7 +174,8 @@ func generateDeprecatedWrappers(c *codegen.Inspector) error {

}

pkgImports := append(methods.Imports(), "github.com/gohugoio/hugo/helpers")
pkgImports := methods.Imports()
// pkgImports := append(methods.Imports(), "github.com/gohugoio/hugo/helpers")

fmt.Fprintf(f, `%s
Expand Down
10 changes: 6 additions & 4 deletions resources/page/page_marshaljson.autogen.go
Expand Up @@ -17,9 +17,6 @@ package page

import (
"encoding/json"
"html/template"
"time"

"github.com/bep/gitmap"
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/config"
Expand All @@ -29,6 +26,8 @@ import (
"github.com/gohugoio/hugo/media"
"github.com/gohugoio/hugo/navigation"
"github.com/gohugoio/hugo/source"
"html/template"
"time"
)

func MarshalPageToJSON(p Page) ([]byte, error) {
Expand Down Expand Up @@ -69,7 +68,8 @@ func MarshalPageToJSON(p Page) ([]byte, error) {
linkTitle := p.LinkTitle()
isNode := p.IsNode()
isPage := p.IsPage()
path := p.Pathc()
path := p.Path()
pathc := p.Pathc()
slug := p.Slug()
lang := p.Lang()
isSection := p.IsSection()
Expand Down Expand Up @@ -127,6 +127,7 @@ func MarshalPageToJSON(p Page) ([]byte, error) {
IsNode bool
IsPage bool
Path string
Pathc string
Slug string
Lang string
IsSection bool
Expand Down Expand Up @@ -183,6 +184,7 @@ func MarshalPageToJSON(p Page) ([]byte, error) {
IsNode: isNode,
IsPage: isPage,
Path: path,
Pathc: pathc,
Slug: slug,
Lang: lang,
IsSection: isSection,
Expand Down
72 changes: 0 additions & 72 deletions resources/page/page_wrappers.autogen.go
Expand Up @@ -15,13 +15,6 @@

package page

import (
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugofs"
"html/template"
)

// NewDeprecatedWarningPage adds deprecation warnings to the given implementation.
func NewDeprecatedWarningPage(p DeprecatedWarningPageMethods) DeprecatedWarningPageMethods {
return &pageDeprecated{p: p}
Expand All @@ -30,68 +23,3 @@ func NewDeprecatedWarningPage(p DeprecatedWarningPageMethods) DeprecatedWarningP
type pageDeprecated struct {
p DeprecatedWarningPageMethods
}

func (p *pageDeprecated) Filename() string {
helpers.Deprecated("Page.Filename", "Use .File.Filename", true)
return p.p.Filename()
}
func (p *pageDeprecated) Dir() string {
helpers.Deprecated("Page.Dir", "Use .File.Dir", true)
return p.p.Dir()
}
func (p *pageDeprecated) IsDraft() bool {
helpers.Deprecated("Page.IsDraft", "Use .Draft.", true)
return p.p.IsDraft()
}
func (p *pageDeprecated) Extension() string {
helpers.Deprecated("Page.Extension", "Use .File.Extension", true)
return p.p.Extension()
}
func (p *pageDeprecated) Hugo() hugo.Info {
helpers.Deprecated("Page.Hugo", "Use the global hugo function.", true)
return p.p.Hugo()
}
func (p *pageDeprecated) Ext() string {
helpers.Deprecated("Page.Ext", "Use .File.Ext", true)
return p.p.Ext()
}
func (p *pageDeprecated) LanguagePrefix() string {
helpers.Deprecated("Page.LanguagePrefix", "Use .Site.LanguagePrefix.", true)
return p.p.LanguagePrefix()
}
func (p *pageDeprecated) GetParam(arg0 string) interface{} {
helpers.Deprecated("Page.GetParam", "Use .Param or .Params.myParam.", true)
return p.p.GetParam(arg0)
}
func (p *pageDeprecated) LogicalName() string {
helpers.Deprecated("Page.LogicalName", "Use .File.LogicalName", true)
return p.p.LogicalName()
}
func (p *pageDeprecated) BaseFileName() string {
helpers.Deprecated("Page.BaseFileName", "Use .File.BaseFileName", true)
return p.p.BaseFileName()
}
func (p *pageDeprecated) RSSLink() template.URL {
helpers.Deprecated("Page.RSSLink", "Use the Output Format's link, e.g. something like:\n {{ with .OutputFormats.Get \"RSS\" }}{{ .RelPermalink }}{{ end }}", true)
return p.p.RSSLink()
}
func (p *pageDeprecated) TranslationBaseName() string {
helpers.Deprecated("Page.TranslationBaseName", "Use .File.TranslationBaseName", true)
return p.p.TranslationBaseName()
}
func (p *pageDeprecated) URL() string {
helpers.Deprecated("Page.URL", "Use .Permalink or .RelPermalink. If what you want is the front matter URL value, use .Params.url", true)
return p.p.URL()
}
func (p *pageDeprecated) ContentBaseName() string {
helpers.Deprecated("Page.ContentBaseName", "Use .File.ContentBaseName", true)
return p.p.ContentBaseName()
}
func (p *pageDeprecated) UniqueID() string {
helpers.Deprecated("Page.UniqueID", "Use .File.UniqueID", true)
return p.p.UniqueID()
}
func (p *pageDeprecated) FileInfo() hugofs.FileMetaInfo {
helpers.Deprecated("Page.FileInfo", "Use .File.FileInfo", true)
return p.p.FileInfo()
}

0 comments on commit 9563c7d

Please sign in to comment.