mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Remove some old and unused deprecation code
This commit is contained in:
parent
4d38f47250
commit
5fa97ee964
3 changed files with 2 additions and 99 deletions
|
@ -339,8 +339,6 @@ type PageWithoutContent interface {
|
||||||
// This is currently only triggered with the Related content feature
|
// This is currently only triggered with the Related content feature
|
||||||
// and the "fragments" type of index.
|
// and the "fragments" type of index.
|
||||||
HeadingsFiltered(context.Context) tableofcontents.Headings
|
HeadingsFiltered(context.Context) tableofcontents.Headings
|
||||||
|
|
||||||
DeprecatedWarningPageMethods
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Positioner provides next/prev navigation.
|
// Positioner provides next/prev navigation.
|
||||||
|
@ -417,7 +415,6 @@ type TableOfContentsProvider interface {
|
||||||
|
|
||||||
// TranslationsProvider provides access to any translations.
|
// TranslationsProvider provides access to any translations.
|
||||||
type TranslationsProvider interface {
|
type TranslationsProvider interface {
|
||||||
|
|
||||||
// IsTranslated returns whether this content file is translated to
|
// IsTranslated returns whether this content file is translated to
|
||||||
// other language(s).
|
// other language(s).
|
||||||
IsTranslated() bool
|
IsTranslated() bool
|
||||||
|
@ -431,7 +428,6 @@ type TranslationsProvider interface {
|
||||||
|
|
||||||
// TreeProvider provides section tree navigation.
|
// TreeProvider provides section tree navigation.
|
||||||
type TreeProvider interface {
|
type TreeProvider interface {
|
||||||
|
|
||||||
// IsAncestor returns whether the current page is an ancestor of other.
|
// IsAncestor returns whether the current page is an ancestor of other.
|
||||||
// Note that this method is not relevant for taxonomy lists and taxonomy terms pages.
|
// Note that this method is not relevant for taxonomy lists and taxonomy terms pages.
|
||||||
IsAncestor(other any) (bool, error)
|
IsAncestor(other any) (bool, error)
|
||||||
|
@ -469,15 +465,6 @@ type TreeProvider interface {
|
||||||
Page() Page
|
Page() Page
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeprecatedWarningPageMethods lists deprecated Page methods that will trigger
|
|
||||||
// a WARNING if invoked.
|
|
||||||
// This was added in Hugo 0.55.
|
|
||||||
type DeprecatedWarningPageMethods any // This was emptied in Hugo 0.93.0.
|
|
||||||
|
|
||||||
// Move here to trigger ERROR instead of WARNING.
|
|
||||||
// TODO(bep) create wrappers and put into the Page once it has some methods.
|
|
||||||
type DeprecatedErrorPageMethods any
|
|
||||||
|
|
||||||
// PageWithContext is a Page with a context.Context.
|
// PageWithContext is a Page with a context.Context.
|
||||||
type PageWithContext struct {
|
type PageWithContext struct {
|
||||||
Page
|
Page
|
||||||
|
|
|
@ -15,13 +15,12 @@ package page_generate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/common/maps"
|
"github.com/gohugoio/hugo/common/maps"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/codegen"
|
"github.com/gohugoio/hugo/codegen"
|
||||||
|
@ -47,8 +46,7 @@ const header = `// Copyright 2019 The Hugo Authors. All rights reserved.
|
||||||
`
|
`
|
||||||
|
|
||||||
var (
|
var (
|
||||||
pageInterfaceDeprecated = reflect.TypeOf((*page.DeprecatedWarningPageMethods)(nil)).Elem()
|
pageInterface = reflect.TypeOf((*page.Page)(nil)).Elem()
|
||||||
pageInterface = reflect.TypeOf((*page.Page)(nil)).Elem()
|
|
||||||
|
|
||||||
packageDir = filepath.FromSlash("resources/page")
|
packageDir = filepath.FromSlash("resources/page")
|
||||||
)
|
)
|
||||||
|
@ -58,10 +56,6 @@ func Generate(c *codegen.Inspector) error {
|
||||||
return fmt.Errorf("failed to generate JSON marshaler: %w", err)
|
return fmt.Errorf("failed to generate JSON marshaler: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := generateDeprecatedWrappers(c); err != nil {
|
|
||||||
return fmt.Errorf("failed to generate deprecate wrappers: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := generateFileIsZeroWrappers(c); err != nil {
|
if err := generateFileIsZeroWrappers(c); err != nil {
|
||||||
return fmt.Errorf("failed to generate file wrappers: %w", err)
|
return fmt.Errorf("failed to generate file wrappers: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -81,10 +75,6 @@ func generateMarshalJSON(c *codegen.Inspector) error {
|
||||||
|
|
||||||
// Exclude these methods
|
// Exclude these methods
|
||||||
excludes := []reflect.Type{
|
excludes := []reflect.Type{
|
||||||
// We need to evaluate the deprecated vs JSON in the future,
|
|
||||||
// but leave them out for now.
|
|
||||||
pageInterfaceDeprecated,
|
|
||||||
|
|
||||||
// Leave this out for now. We need to revisit the author issue.
|
// Leave this out for now. We need to revisit the author issue.
|
||||||
reflect.TypeOf((*page.AuthorProvider)(nil)).Elem(),
|
reflect.TypeOf((*page.AuthorProvider)(nil)).Elem(),
|
||||||
|
|
||||||
|
@ -133,71 +123,6 @@ package page
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateDeprecatedWrappers(c *codegen.Inspector) error {
|
|
||||||
filename := filepath.Join(c.ProjectRootDir, packageDir, "page_wrappers.autogen.go")
|
|
||||||
f, err := os.Create(filename)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
// Generate a wrapper for deprecated page methods
|
|
||||||
|
|
||||||
reasons := map[string]string{
|
|
||||||
"IsDraft": "Use .Draft.",
|
|
||||||
"Hugo": "Use the global hugo function.",
|
|
||||||
"LanguagePrefix": "Use .Site.LanguagePrefix.",
|
|
||||||
"GetParam": "Use .Param or .Params.myParam.",
|
|
||||||
"RSSLink": `Use the Output Format's link, e.g. something like:
|
|
||||||
{{ with .OutputFormats.Get "RSS" }}{{ .RelPermalink }}{{ end }}`,
|
|
||||||
"URL": "Use .Permalink or .RelPermalink. If what you want is the front matter URL value, use .Params.url",
|
|
||||||
}
|
|
||||||
|
|
||||||
deprecated := func(name string, tp reflect.Type) string {
|
|
||||||
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{pageInterfaceDeprecated}, nil)
|
|
||||||
|
|
||||||
for _, m := range methods {
|
|
||||||
fmt.Fprint(&buff, m.Declaration("*pageDeprecated"))
|
|
||||||
fmt.Fprintln(&buff, " {")
|
|
||||||
fmt.Fprintf(&buff, "\t%s\n", deprecated(m.Name, m.Owner))
|
|
||||||
fmt.Fprintf(&buff, "\t%s\n}\n", m.Delegate("p", "p"))
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
pkgImports := methods.Imports()
|
|
||||||
// pkgImports := append(methods.Imports(), "github.com/gohugoio/hugo/helpers")
|
|
||||||
|
|
||||||
fmt.Fprintf(f, `%s
|
|
||||||
|
|
||||||
package page
|
|
||||||
|
|
||||||
%s
|
|
||||||
// NewDeprecatedWarningPage adds deprecation warnings to the given implementation.
|
|
||||||
func NewDeprecatedWarningPage(p DeprecatedWarningPageMethods) DeprecatedWarningPageMethods {
|
|
||||||
return &pageDeprecated{p: p}
|
|
||||||
}
|
|
||||||
|
|
||||||
type pageDeprecated struct {
|
|
||||||
p DeprecatedWarningPageMethods
|
|
||||||
}
|
|
||||||
|
|
||||||
%s
|
|
||||||
|
|
||||||
`, header, importsString(pkgImports), buff.String())
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func generateFileIsZeroWrappers(c *codegen.Inspector) error {
|
func generateFileIsZeroWrappers(c *codegen.Inspector) error {
|
||||||
filename := filepath.Join(c.ProjectRootDir, packageDir, "zero_file.autogen.go")
|
filename := filepath.Join(c.ProjectRootDir, packageDir, "zero_file.autogen.go")
|
||||||
f, err := os.Create(filename)
|
f, err := os.Create(filename)
|
||||||
|
|
|
@ -14,12 +14,3 @@
|
||||||
// This file is autogenerated.
|
// This file is autogenerated.
|
||||||
|
|
||||||
package page
|
package page
|
||||||
|
|
||||||
// NewDeprecatedWarningPage adds deprecation warnings to the given implementation.
|
|
||||||
func NewDeprecatedWarningPage(p DeprecatedWarningPageMethods) DeprecatedWarningPageMethods {
|
|
||||||
return &pageDeprecated{p: p}
|
|
||||||
}
|
|
||||||
|
|
||||||
type pageDeprecated struct {
|
|
||||||
p DeprecatedWarningPageMethods
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue