Some godoc adjustments and image struct renames

This commit is contained in:
Bjørn Erik Pedersen
2022-04-21 10:59:13 +02:00
parent 11047534e4
commit fa80fe3c8a
23 changed files with 193 additions and 90 deletions

View File

@@ -161,8 +161,7 @@ type PageMetaProvider interface {
// Aliases forms the base for redirects generation.
Aliases() []string
// BundleType returns the bundle type: "leaf", "branch" or an empty string if it is none.
// See https://gohugo.io/content-management/page-bundles/
// BundleType returns the bundle type: `leaf`, `branch` or an empty string.
BundleType() files.ContentClass
// A configured description.

View File

@@ -40,7 +40,10 @@ var (
// PageGroup represents a group of pages, grouped by the key.
// The key is typically a year or similar.
type PageGroup struct {
// The key, typically a year or similar.
Key any
// The Pages in this group.
Pages
}
@@ -361,6 +364,7 @@ func (p Pages) GroupByParamDate(key string, format string, order ...string) (Pag
}
// ProbablyEq wraps compare.ProbablyEqer
// For internal use.
func (p PageGroup) ProbablyEq(other any) bool {
otherP, ok := other.(PageGroup)
if !ok {
@@ -374,7 +378,7 @@ func (p PageGroup) ProbablyEq(other any) bool {
return p.Pages.ProbablyEq(otherP.Pages)
}
// Slice is not meant to be used externally. It's a bridge function
// Slice is for internal use.
// for the template functions. See collections.Slice.
func (p PageGroup) Slice(in any) (any, error) {
switch items := in.(type) {

View File

@@ -22,9 +22,11 @@ import (
"github.com/gohugoio/hugo/resources/resource"
)
// Pages is a slice of pages. This is the most common list type in Hugo.
// Pages is a slice of Page objects. This is the most common list type in Hugo.
type Pages []Page
// String returns a string representation of the list.
// For internal use.
func (ps Pages) String() string {
return fmt.Sprintf("Pages(%d)", len(ps))
}
@@ -37,7 +39,8 @@ func (ps Pages) shuffle() {
}
}
// ToResources wraps resource.ResourcesConverter
// ToResources wraps resource.ResourcesConverter.
// For internal use.
func (pages Pages) ToResources() resource.Resources {
r := make(resource.Resources, len(pages))
for i, p := range pages {
@@ -86,10 +89,12 @@ func ToPages(seq any) (Pages, error) {
return nil, fmt.Errorf("cannot convert type %T to Pages", seq)
}
// Group groups the pages in in by key.
// This implements collections.Grouper.
func (p Pages) Group(key any, in any) (any, error) {
pages, err := ToPages(in)
if err != nil {
return nil, err
return PageGroup{}, err
}
return PageGroup{Key: key, Pages: pages}, nil
}
@@ -100,6 +105,7 @@ func (p Pages) Len() int {
}
// ProbablyEq wraps compare.ProbablyEqer
// For internal use.
func (pages Pages) ProbablyEq(other any) bool {
otherPages, ok := other.(Pages)
if !ok {

View File

@@ -29,21 +29,52 @@ import (
// Site represents a site in the build. This is currently a very narrow interface,
// but the actual implementation will be richer, see hugolib.SiteInfo.
type Site interface {
// Returns the Language configured for this Site.
Language() *langs.Language
// Returns all the regular Pages in this Site.
RegularPages() Pages
// Returns all Pages in this Site.
Pages() Pages
// A shortcut to the home page.
Home() Page
// Returns true if we're running in a server.
IsServer() bool
// Returns the server port.
ServerPort() int
// Returns the configured title for this Site.
Title() string
// Returns all Sites for all languages.
Sites() Sites
// Returns Site currently rendering.
Current() Site
// Returns a struct with some information about the build.
Hugo() hugo.Info
// Returns the BaseURL for this Site.
BaseURL() template.URL
// Retuns a taxonomy map.
Taxonomies() any
// Returns the last modification date of the content.
LastChange() time.Time
// Returns the Menus for this site.
Menus() navigation.Menus
// Returns the Params configured for this site.
Params() maps.Params
// Returns a map of all the data inside /data.
Data() map[string]any
}

View File

@@ -63,7 +63,7 @@ func (w WeightedPage) String() string {
return fmt.Sprintf("WeightedPage(%d,%q)", w.Weight, w.Page.Title())
}
// Slice is not meant to be used externally. It's a bridge function
// Slice is for internal use.
// for the template functions. See collections.Slice.
func (p WeightedPage) Slice(in any) (any, error) {
switch items := in.(type) {