page

package
v0.128.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2024 License: Apache-2.0 Imports: 50 Imported by: 20

Documentation

Overview

Package page contains the core interfaces and types for the Page resource, a core component in Hugo.

Package page contains the core interfaces and types for the Page resource, a core component in Hugo.

Package page contains the core interfaces and types for the Page resource, a core component in Hugo.

Package page contains the core interfaces and types for the Page resource, a core component in Hugo.

Index

Constants

This section is empty.

Variables

View Source
var (
	NopPage                 Page            = new(nopPage)
	NopContentRenderer      ContentRenderer = new(nopContentRenderer)
	NopCPageContentRenderer                 = struct {
		OutputFormatPageContentProvider
		ContentRenderer
	}{
		NopPage,
		NopContentRenderer,
	}
	NilPage *nopPage
)
View Source
var (

	// DefaultPageSort is the default sort func for pages in Hugo:
	// Order by Ordinal, Weight, Date, LinkTitle and then full file path.
	DefaultPageSort = func(p1, p2 Page) bool {
		o1, o2 := getOrdinals(p1, p2)
		if o1 != o2 && o1 != -1 && o2 != -1 {
			return o1 < o2
		}

		w01, w02 := getWeight0s(p1, p2)
		if w01 != w02 && w01 != -1 && w02 != -1 {
			return w01 < w02
		}
		if p1.Weight() == p2.Weight() {
			if p1.Date().Unix() == p2.Date().Unix() {
				c := collatorStringCompare(func(p Page) string { return p.LinkTitle() }, p1, p2)
				if c == 0 {
					if p1.File() == nil || p2.File() == nil {
						return p1.File() == nil
					}
					return compare.LessStrings(p1.File().Filename(), p2.File().Filename())
				}
				return c < 0
			}
			return p1.Date().Unix() > p2.Date().Unix()
		}

		if p2.Weight() == 0 {
			return true
		}

		if p1.Weight() == 0 {
			return false
		}

		return p1.Weight() < p2.Weight()
	}
)

Functions

func CheckCascadePattern added in v0.123.4

func CheckCascadePattern(logger loggers.Logger, m PageMatcher)

func Clear

func Clear() error

Clear clears any global package state.

func DecodeCascade added in v0.86.0

func DecodeCascade(logger loggers.Logger, in any) (map[PageMatcher]maps.Params, error)

DecodeCascade decodes in which could be either a map or a slice of maps.

func DecodeCascadeConfig added in v0.112.0

func DecodeCascadeConfig(logger loggers.Logger, in any) (*config.ConfigNamespace[[]PageMatcherParamsConfig, map[PageMatcher]maps.Params], error)

func DecodePermalinksConfig added in v0.115.0

func DecodePermalinksConfig(m map[string]any) (map[string]map[string]string, error)

DecodePermalinksConfig decodes the permalinks configuration in the given map

func MarshalPageToJSON

func MarshalPageToJSON(p Page) ([]byte, error)

func ResolvePagerSize

func ResolvePagerSize(conf config.AllProvider, options ...any) (int, error)

func SortByDefault

func SortByDefault(pages Pages)

SortByDefault sorts pages by the default sort.

func SortByLanguage

func SortByLanguage(pages Pages)

SortByLanguage sorts the pages by language.

Types

type AlternativeOutputFormatsProvider

type AlternativeOutputFormatsProvider interface {
	// AlternativeOutputFormats gives the alternative output formats for the
	// current output.
	// Note that we use the term "alternative" and not "alternate" here, as it
	// does not necessarily replace the other format, it is an alternative representation.
	AlternativeOutputFormats() OutputFormats
}

AlternativeOutputFormatsProvider provides alternative output formats for a Page.

type Author

type Author struct {
	GivenName   string
	FamilyName  string
	DisplayName string
	Thumbnail   string
	Image       string
	ShortBio    string
	LongBio     string
	Email       string
	Social      AuthorSocial
}

Author contains details about the author of a page. Deprecated: Use taxonomies instead.

type AuthorList

type AuthorList map[string]Author

AuthorList is a list of all authors and their metadata. Deprecated: Use taxonomies instead.

type AuthorProvider

type AuthorProvider interface {
	// Deprecated: Use taxonomies instead.
	Author() Author
	// Deprecated: Use taxonomies instead.
	Authors() AuthorList
}

AuthorProvider provides author information.

type AuthorSocial

type AuthorSocial map[string]string

AuthorSocial is a place to put social details per author. These are the standard keys that themes will expect to have available, but can be expanded to any others on a per site basis - website - github - facebook - twitter - pinterest - instagram - youtube - linkedin - skype Deprecated: Use taxonomies instead.

type ChildCareProvider

type ChildCareProvider interface {
	// Pages returns a list of pages of all kinds.
	Pages() Pages

	// RegularPages returns a list of pages of kind 'Page'.
	RegularPages() Pages

	// RegularPagesRecursive returns all regular pages below the current
	// section.
	RegularPagesRecursive() Pages

	// Resources returns a list of all resources.
	Resources() resource.Resources
}

ChildCareProvider provides accessors to child resources.

type ContentProvider

type ContentProvider interface {
	Content(context.Context) (any, error)

	// Plain returns the Page Content stripped of HTML markup.
	Plain(context.Context) string

	// PlainWords returns a string slice from splitting Plain using https://pkg.go.dev/strings#Fields.
	PlainWords(context.Context) []string

	// Summary returns a generated summary of the content.
	// The breakpoint can be set manually by inserting a summary separator in the source file.
	Summary(context.Context) template.HTML

	// Truncated returns whether the Summary  is truncated or not.
	Truncated(context.Context) bool

	// FuzzyWordCount returns the approximate number of words in the content.
	FuzzyWordCount(context.Context) int

	// WordCount returns the number of words in the content.
	WordCount(context.Context) int

	// ReadingTime returns the reading time based on the length of plain text.
	ReadingTime(context.Context) int

	// Len returns the length of the content.
	// This is for internal use only.
	Len(context.Context) int
}

ContentProvider provides the content related values for a Page.

type ContentRenderer added in v0.105.0

type ContentRenderer interface {
	// ParseAndRenderContent renders the given content.
	// For internal use only.
	ParseAndRenderContent(ctx context.Context, content []byte, enableTOC bool) (converter.ResultRender, error)
	// For internal use only.
	ParseContent(ctx context.Context, content []byte) (converter.ResultParse, bool, error)
	// For internal use only.
	RenderContent(ctx context.Context, content []byte, doc any) (converter.ResultRender, bool, error)
}

ContentRenderer provides the content rendering methods for some content.

type Data

type Data map[string]any

Data represents the .Data element in a Page in Hugo. We make this a type so we can do lazy loading of .Data.Pages

func (Data) Pages

func (d Data) Pages() Pages

Pages returns the pages stored with key "pages". If this is a func, it will be invoked.

type FileProvider

type FileProvider interface {
	// File returns the source file for this Page,
	// or a zero File if this Page is not backed by a file.
	File() *source.File
}

FileProvider provides the source file.

type GetPageProvider

type GetPageProvider interface {
	// GetPage looks up a page for the given ref.
	//    {{ with .GetPage "blog" }}{{ .Title }}{{ end }}
	//
	// This will return nil when no page could be found, and will return
	// an error if the ref is ambiguous.
	GetPage(ref string) (Page, error)
}

GetPageProvider provides the GetPage method.

type GitInfoProvider

type GitInfoProvider interface {
	// GitInfo returns the Git info for this object.
	GitInfo() source.GitInfo
	// CodeOwners returns the code owners for this object.
	CodeOwners() []string
}

GitInfoProvider provides Git info.

type InSectionPositioner

type InSectionPositioner interface {
	// NextInSection returns the next page in the same section.
	NextInSection() Page
	// PrevInSection returns the previous page in the same section.
	PrevInSection() Page
}

InSectionPositioner provides section navigation.

type InternalDependencies

type InternalDependencies interface {
	// GetRelatedDocsHandler is for internal use only.
	GetRelatedDocsHandler() *RelatedDocsHandler
}

InternalDependencies is considered an internal interface.

type LazyContentProvider added in v0.92.0

type LazyContentProvider struct {
	// contains filtered or unexported fields
}

LazyContentProvider initializes itself when read. Each method of the ContentProvider interface initializes a content provider and shares it with other methods.

Used in cases where we cannot guarantee whether the content provider will be needed. Must create via NewLazyContentProvider.

func NewLazyContentProvider added in v0.92.0

func NewLazyContentProvider(f func() (OutputFormatContentProvider, error)) *LazyContentProvider

NewLazyContentProvider returns a LazyContentProvider initialized with function f. The resulting LazyContentProvider calls f in order to retrieve a ContentProvider

func (*LazyContentProvider) Content added in v0.92.0

func (lcp *LazyContentProvider) Content(ctx context.Context) (any, error)

func (*LazyContentProvider) Fragments added in v0.111.2

func (*LazyContentProvider) FuzzyWordCount added in v0.92.0

func (lcp *LazyContentProvider) FuzzyWordCount(ctx context.Context) int

func (*LazyContentProvider) Len added in v0.92.0

func (lcp *LazyContentProvider) Len(ctx context.Context) int

func (*LazyContentProvider) ParseAndRenderContent added in v0.111.0

func (lcp *LazyContentProvider) ParseAndRenderContent(ctx context.Context, content []byte, renderTOC bool) (converter.ResultRender, error)

func (*LazyContentProvider) ParseContent added in v0.111.0

func (lcp *LazyContentProvider) ParseContent(ctx context.Context, content []byte) (converter.ResultParse, bool, error)

func (*LazyContentProvider) Plain added in v0.92.0

func (lcp *LazyContentProvider) Plain(ctx context.Context) string

func (*LazyContentProvider) PlainWords added in v0.92.0

func (lcp *LazyContentProvider) PlainWords(ctx context.Context) []string

func (*LazyContentProvider) ReadingTime added in v0.92.0

func (lcp *LazyContentProvider) ReadingTime(ctx context.Context) int

func (*LazyContentProvider) Render added in v0.92.1

func (lcp *LazyContentProvider) Render(ctx context.Context, layout ...string) (template.HTML, error)

func (*LazyContentProvider) RenderContent added in v0.105.0

func (lcp *LazyContentProvider) RenderContent(ctx context.Context, content []byte, doc any) (converter.ResultRender, bool, error)

func (*LazyContentProvider) RenderString added in v0.92.1

func (lcp *LazyContentProvider) RenderString(ctx context.Context, args ...any) (template.HTML, error)

func (*LazyContentProvider) Reset added in v0.92.0

func (lcp *LazyContentProvider) Reset()

func (*LazyContentProvider) Summary added in v0.92.0

func (lcp *LazyContentProvider) Summary(ctx context.Context) template.HTML

func (*LazyContentProvider) TableOfContents added in v0.92.1

func (lcp *LazyContentProvider) TableOfContents(ctx context.Context) template.HTML

func (*LazyContentProvider) Truncated added in v0.92.0

func (lcp *LazyContentProvider) Truncated(ctx context.Context) bool

func (*LazyContentProvider) WordCount added in v0.92.0

func (lcp *LazyContentProvider) WordCount(ctx context.Context) int

type OrderedTaxonomy added in v0.110.0

type OrderedTaxonomy []OrderedTaxonomyEntry

OrderedTaxonomy is another representation of an Taxonomy using an array rather than a map. Important because you can't order a map.

func (OrderedTaxonomy) Reverse added in v0.110.0

func (t OrderedTaxonomy) Reverse() OrderedTaxonomy

Reverse reverses the order of the entries in this taxonomy.

type OrderedTaxonomyEntry added in v0.110.0

type OrderedTaxonomyEntry struct {
	Name string
	WeightedPages
}

OrderedTaxonomyEntry is similar to an element of a Taxonomy, but with the key embedded (as name) e.g: {Name: Technology, WeightedPages: TaxonomyPages}

func (OrderedTaxonomyEntry) Count added in v0.110.0

func (ie OrderedTaxonomyEntry) Count() int

Count returns the count the pages in this taxonomy.

func (OrderedTaxonomyEntry) Pages added in v0.110.0

func (ie OrderedTaxonomyEntry) Pages() Pages

Pages returns the Pages for this taxonomy.

func (OrderedTaxonomyEntry) Term added in v0.110.0

func (ie OrderedTaxonomyEntry) Term() string

Term returns the name given to this taxonomy.

type OutputFormat

type OutputFormat struct {
	// Rel contains a value that can be used to construct a rel link.
	// This is value is fetched from the output format definition.
	// Note that for pages with only one output format,
	// this method will always return "canonical".
	// As an example, the AMP output format will, by default, return "amphtml".
	//
	// See:
	// https://www.ampproject.org/docs/guides/deploy/discovery
	//
	// Most other output formats will have "alternate" as value for this.
	Rel string

	Format output.Format
	// contains filtered or unexported fields
}

OutputFormat links to a representation of a resource.

func NewOutputFormat

func NewOutputFormat(relPermalink, permalink string, isCanonical bool, f output.Format) OutputFormat

func (OutputFormat) MediaType

func (o OutputFormat) MediaType() media.Type

MediaType returns this OutputFormat's MediaType (MIME type).

func (OutputFormat) Name

func (o OutputFormat) Name() string

Name returns this OutputFormat's name, i.e. HTML, AMP, JSON etc.

func (o OutputFormat) Permalink() string

Permalink returns the absolute permalink to this output format.

func (o OutputFormat) RelPermalink() string

RelPermalink returns the relative permalink to this output format.

type OutputFormatContentProvider added in v0.92.1

type OutputFormatContentProvider interface {
	OutputFormatPageContentProvider

	// for internal use.
	ContentRenderer
}

OutputFormatContentProvider represents the method set that is "outputFormat aware" and that we provide lazy initialization for in case they get invoked outside of their normal rendering context, e.g. via .Translations. Note that this set is currently not complete, but should cover the most common use cases. For the others, the implementation will be from the page.NoopPage.

type OutputFormatPageContentProvider added in v0.105.0

type OutputFormatPageContentProvider interface {
	ContentProvider
	TableOfContentsProvider
	PageRenderProvider
}

OutputFormatPageContentProvider holds the exported methods from Page that are "outputFormat aware".

type OutputFormats

type OutputFormats []OutputFormat

OutputFormats holds a list of the relevant output formats for a given page.

func (OutputFormats) Get

func (o OutputFormats) Get(name string) *OutputFormat

Get gets a OutputFormat given its name, i.e. json, html etc. It returns nil if none found.

type OutputFormatsProvider

type OutputFormatsProvider interface {
	// OutputFormats returns the OutputFormats for this Page.
	OutputFormats() OutputFormats
}

OutputFormatsProvider provides the OutputFormats of a Page.

type Page

Page is the core interface in Hugo and what you get as the top level data context in your templates.

type PageFragment added in v0.111.0

type PageGenealogist

type PageGenealogist interface {
	// Template example:
	// {{ $related := .RegularPages.Related . }}
	Related(ctx context.Context, opts any) (Pages, error)

	// Template example:
	// {{ $related := .RegularPages.RelatedIndices . "tags" "date" }}
	// Deprecated: Use Related instead.
	RelatedIndices(ctx context.Context, doc related.Document, indices ...any) (Pages, error)

	// Template example:
	// {{ $related := .RegularPages.RelatedTo ( keyVals "tags" "hugo", "rocks")  ( keyVals "date" .Date ) }}
	// Deprecated: Use Related instead.
	RelatedTo(ctx context.Context, args ...types.KeyValues) (Pages, error)
}

A PageGenealogist finds related pages in a page collection. This interface is implemented by Pages and PageGroup, which makes it available as `{{ .RegularRelated . }}` etc.

type PageGroup

type PageGroup struct {
	// The key, typically a year or similar.
	Key any

	// The Pages in this group.
	Pages
}

PageGroup represents a group of pages, grouped by the key. The key is typically a year or similar.

func (PageGroup) ProbablyEq

func (p PageGroup) ProbablyEq(other any) bool

ProbablyEq wraps compare.ProbablyEqer For internal use.

func (PageGroup) Slice

func (p PageGroup) Slice(in any) (any, error)

Slice is for internal use. for the template functions. See collections.Slice.

type PageMatcher added in v0.76.0

type PageMatcher struct {
	// A Glob pattern matching the content path below /content.
	// Expects Unix-styled slashes.
	// Note that this is the virtual path, so it starts at the mount root
	// with a leading "/".
	Path string

	// A Glob pattern matching the Page's Kind(s), e.g. "{home,section}"
	Kind string

	// A Glob pattern matching the Page's language, e.g. "{en,sv}".
	Lang string

	// A Glob pattern matching the Page's Environment, e.g. "{production,development}".
	Environment string
}

A PageMatcher can be used to match a Page with Glob patterns. Note that the pattern matching is case insensitive.

func (PageMatcher) Matches added in v0.76.0

func (m PageMatcher) Matches(p Page) bool

Matches returns whether p matches this matcher.

type PageMatcherParamsConfig added in v0.112.0

type PageMatcherParamsConfig struct {
	// Apply Params to all Pages matching Target.
	Params maps.Params
	Target PageMatcher
}

type PageMetaInternalProvider added in v0.125.6

type PageMetaInternalProvider interface {
	// This is for internal use only.
	PathInfo() *paths.Path
}

PageMetaInternalProvider provides internal page metadata.

type PageMetaProvider

type PageMetaProvider interface {
	// The 4 page dates
	resource.Dated

	// Aliases forms the base for redirects generation.
	Aliases() []string

	// BundleType returns the bundle type: `leaf`, `branch` or an empty string.
	BundleType() string

	// A configured description.
	Description() string

	// Whether this is a draft. Will only be true if run with the --buildDrafts (-D) flag.
	Draft() bool

	// IsHome returns whether this is the home page.
	IsHome() bool

	// Configured keywords.
	Keywords() []string

	// The Page Kind. One of page, home, section, taxonomy, term.
	Kind() string

	// The configured layout to use to render this page. Typically set in front matter.
	Layout() string

	// The title used for links.
	LinkTitle() string

	// IsNode returns whether this is an item of one of the list types in Hugo,
	// i.e. not a regular content
	IsNode() bool

	// IsPage returns whether this is a regular content
	IsPage() bool

	// Param looks for a param in Page and then in Site config.
	Param(key any) (any, error)

	// Path gets the relative path, including file name and extension if relevant,
	// to the source of this Page. It will be relative to any content root.
	Path() string

	// The slug, typically defined in front matter.
	Slug() string

	// This page's language code. Will be the same as the site's.
	Lang() string

	// IsSection returns whether this is a section
	IsSection() bool

	// Section returns the first path element below the content root.
	Section() string

	// Sitemap returns the sitemap configuration for this page.
	// This is for internal use only.
	Sitemap() config.SitemapConfig

	// Type is a discriminator used to select layouts etc. It is typically set
	// in front matter, but will fall back to the root section.
	Type() string

	// The configured weight, used as the first sort value in the default
	// page sort if non-zero.
	Weight() int
}

PageMetaProvider provides page metadata, typically provided via front matter.

type PageProvider added in v0.123.0

type PageProvider interface {
	Page() Page
}

PageProvider provides access to a Page. Implemented by shortcodes and others.

type PageRenderProvider

type PageRenderProvider interface {
	// Render renders the given layout with this Page as context.
	Render(ctx context.Context, layout ...string) (template.HTML, error)
	// RenderString renders the first value in args with tPaginatorhe content renderer defined
	// for this Page.
	// It takes an optional map as a second argument:
	//
	// display (“inline”):
	// - inline or block. If inline (default), surrounding <p></p> on short snippets will be trimmed.
	// markup (defaults to the Page’s markup)
	RenderString(ctx context.Context, args ...any) (template.HTML, error)
}

PageRenderProvider provides a way for a Page to render content.

type PageWithContext added in v0.111.2

type PageWithContext struct {
	Page
	Ctx context.Context
}

PageWithContext is a Page with a context.Context.

func (PageWithContext) Content added in v0.111.2

func (p PageWithContext) Content() (any, error)

func (PageWithContext) FuzzyWordCount added in v0.111.2

func (p PageWithContext) FuzzyWordCount() int

func (PageWithContext) Len added in v0.111.2

func (p PageWithContext) Len() int

func (PageWithContext) Plain added in v0.111.2

func (p PageWithContext) Plain() string

func (PageWithContext) PlainWords added in v0.111.2

func (p PageWithContext) PlainWords() []string

func (PageWithContext) ReadingTime added in v0.111.2

func (p PageWithContext) ReadingTime() int

func (PageWithContext) Summary added in v0.111.2

func (p PageWithContext) Summary() template.HTML

func (PageWithContext) Truncated added in v0.111.2

func (p PageWithContext) Truncated() bool

func (PageWithContext) WordCount added in v0.111.2

func (p PageWithContext) WordCount() int

type PageWithoutContent

type PageWithoutContent interface {
	RawContentProvider
	RenderShortcodesProvider
	resource.Resource
	PageMetaProvider
	PageMetaInternalProvider
	resource.LanguageProvider

	// For pages backed by a file.
	FileProvider

	GitInfoProvider

	// Output formats
	OutputFormatsProvider
	AlternativeOutputFormatsProvider

	// Tree navigation
	ChildCareProvider
	TreeProvider

	// Horizontal navigation
	InSectionPositioner
	PageRenderProvider
	PaginatorProvider
	Positioner
	navigation.PageMenusProvider

	// TODO(bep)
	AuthorProvider

	// Page lookups/refs
	GetPageProvider
	RefProvider

	resource.TranslationKeyProvider
	TranslationsProvider

	SitesProvider

	// Helper methods
	ShortcodeInfoProvider
	compare.Eqer

	// Scratch returns a Scratch that can be used to store temporary state.
	// Note that this Scratch gets reset on server rebuilds. See Store() for a variant that survives.
	maps.Scratcher

	// Store returns a Scratch that can be used to store temporary state.
	// In contrast to Scratch(), this Scratch is not reset on server rebuilds.
	Store() *maps.Scratch

	RelatedKeywordsProvider

	// GetTerms gets the terms of a given taxonomy,
	// e.g. GetTerms("categories")
	GetTerms(taxonomy string) Pages

	// HeadingsFiltered returns the headings for this page when a filter is set.
	// This is currently only triggered with the Related content feature
	// and the "fragments" type of index.
	HeadingsFiltered(context.Context) tableofcontents.Headings
}

PageWithoutContent is the Page without any of the content methods.

type Pager

type Pager struct {
	*Paginator
	// contains filtered or unexported fields
}

Pager represents one of the elements in a paginator. The number, starting on 1, represents its place.

func (*Pager) First

func (p *Pager) First() *Pager

First returns the pager for the first page.

func (*Pager) HasNext

func (p *Pager) HasNext() bool

HasNext tests whether there are page(s) after the current.

func (*Pager) HasPrev

func (p *Pager) HasPrev() bool

HasPrev tests whether there are page(s) before the current.

func (*Pager) Last

func (p *Pager) Last() *Pager

Last returns the pager for the last page.

func (*Pager) Next

func (p *Pager) Next() *Pager

Next returns the pager for the next page.

func (*Pager) NumberOfElements

func (p *Pager) NumberOfElements() int

NumberOfElements gets the number of elements on this page.

func (*Pager) PageGroups

func (p *Pager) PageGroups() PagesGroup

PageGroups return Page groups for this page. Note: If this return non-empty result, then Pages() will return empty.

func (*Pager) PageNumber

func (p *Pager) PageNumber() int

PageNumber returns the current page's number in the pager sequence.

func (*Pager) Pages

func (p *Pager) Pages() Pages

Pages returns the Pages on this page. Note: If this return a non-empty result, then PageGroups() will return empty.

func (*Pager) Prev

func (p *Pager) Prev() *Pager

Prev returns the pager for the previous page.

func (Pager) String

func (p Pager) String() string

func (*Pager) URL

func (p *Pager) URL() string

URL returns the URL to the current page.

type Pages

type Pages []Page

Pages is a slice of Page objects. This is the most common list type in Hugo.

func ToPages

func ToPages(seq any) (Pages, error)

ToPages tries to convert seq into Pages.

func (Pages) ByDate

func (p Pages) ByDate() Pages

ByDate sorts the Pages by date and returns a copy.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) ByExpiryDate

func (p Pages) ByExpiryDate() Pages

ByExpiryDate sorts the Pages by publish date and returns a copy.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) ByLanguage

func (p Pages) ByLanguage() Pages

ByLanguage sorts the Pages by the language's Weight.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) ByLastmod

func (p Pages) ByLastmod() Pages

ByLastmod sorts the Pages by the last modification date and returns a copy.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) ByLength

func (p Pages) ByLength(ctx context.Context) Pages

ByLength sorts the Pages by length and returns a copy.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) ByLinkTitle

func (p Pages) ByLinkTitle() Pages

ByLinkTitle sorts the Pages by link title and returns a copy.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) ByParam

func (p Pages) ByParam(paramsKey any) Pages

ByParam sorts the pages according to the given page Params key.

Adjacent invocations on the same receiver with the same paramsKey will return a cached result.

This may safely be executed in parallel.

func (Pages) ByPublishDate

func (p Pages) ByPublishDate() Pages

ByPublishDate sorts the Pages by publish date and returns a copy.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) ByTitle

func (p Pages) ByTitle() Pages

ByTitle sorts the Pages by title and returns a copy.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) ByWeight

func (p Pages) ByWeight() Pages

ByWeight sorts the Pages by weight and returns a copy.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) Group

func (p Pages) Group(key any, in any) (any, error)

Group groups the pages in in by key. This implements collections.Grouper.

func (Pages) GroupBy

func (p Pages) GroupBy(ctx context.Context, key string, order ...string) (PagesGroup, error)

GroupBy groups by the value in the given field or method name and with the given order. Valid values for order is asc, desc, rev and reverse.

func (Pages) GroupByDate

func (p Pages) GroupByDate(format string, order ...string) (PagesGroup, error)

GroupByDate groups by the given page's Date value in the given format and with the given order. Valid values for order is asc, desc, rev and reverse. For valid format strings, see https://golang.org/pkg/time/#Time.Format

func (Pages) GroupByExpiryDate

func (p Pages) GroupByExpiryDate(format string, order ...string) (PagesGroup, error)

GroupByExpiryDate groups by the given page's ExpireDate value in the given format and with the given order. Valid values for order is asc, desc, rev and reverse. For valid format strings, see https://golang.org/pkg/time/#Time.Format

func (Pages) GroupByLastmod added in v0.73.0

func (p Pages) GroupByLastmod(format string, order ...string) (PagesGroup, error)

GroupByLastmod groups by the given page's Lastmod value in the given format and with the given order. Valid values for order is asc, desc, rev and reverse. For valid format strings, see https://golang.org/pkg/time/#Time.Format

func (Pages) GroupByParam

func (p Pages) GroupByParam(key string, order ...string) (PagesGroup, error)

GroupByParam groups by the given page parameter key's value and with the given order. Valid values for order is asc, desc, rev and reverse.

func (Pages) GroupByParamDate

func (p Pages) GroupByParamDate(key string, format string, order ...string) (PagesGroup, error)

GroupByParamDate groups by a date set as a param on the page in the given format and with the given order. Valid values for order is asc, desc, rev and reverse. For valid format strings, see https://golang.org/pkg/time/#Time.Format

func (Pages) GroupByPublishDate

func (p Pages) GroupByPublishDate(format string, order ...string) (PagesGroup, error)

GroupByPublishDate groups by the given page's PublishDate value in the given format and with the given order. Valid values for order is asc, desc, rev and reverse. For valid format strings, see https://golang.org/pkg/time/#Time.Format

func (Pages) Len

func (p Pages) Len() int

Len returns the number of pages in the list.

func (Pages) Limit

func (p Pages) Limit(n int) Pages

Limit limits the number of pages returned to n.

func (Pages) MergeByLanguage

func (p1 Pages) MergeByLanguage(p2 Pages) Pages

MergeByLanguage supplies missing translations in p1 with values from p2. The result is sorted by the default sort order for pages.

func (Pages) MergeByLanguageInterface

func (p1 Pages) MergeByLanguageInterface(in any) (any, error)

MergeByLanguageInterface is the generic version of MergeByLanguage. It is here just so it can be called from the tpl package. This is for internal use.

func (Pages) Next

func (p Pages) Next(cur Page) Page

Next returns the next page relative to the given

func (Pages) Prev

func (p Pages) Prev(cur Page) Page

Prev returns the previous page relative to the given

func (Pages) ProbablyEq

func (pages Pages) ProbablyEq(other any) bool

ProbablyEq wraps compare.ProbablyEqer For internal use.

func (Pages) Related

func (p Pages) Related(ctx context.Context, optsv any) (Pages, error)

Related searches all the configured indices with the search keywords from the supplied document.

func (Pages) RelatedIndices

func (p Pages) RelatedIndices(ctx context.Context, doc related.Document, indices ...any) (Pages, error)

RelatedIndices searches the given indices with the search keywords from the supplied document. Deprecated: Use Related instead.

func (Pages) RelatedTo

func (p Pages) RelatedTo(ctx context.Context, args ...types.KeyValues) (Pages, error)

RelatedTo searches the given indices with the corresponding values. Deprecated: Use Related instead.

func (Pages) Reverse

func (p Pages) Reverse() Pages

Reverse reverses the order in Pages and returns a copy.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) String

func (ps Pages) String() string

String returns a string representation of the list. For internal use.

func (Pages) ToResources

func (pages Pages) ToResources() resource.Resources

ToResources wraps resource.ResourcesConverter. For internal use.

type PagesFactory

type PagesFactory func() Pages

PagesFactory somehow creates some Pages. We do a lot of lazy Pages initialization in Hugo, so we need a type.

type PagesGroup

type PagesGroup []PageGroup

PagesGroup represents a list of page groups. This is what you get when doing page grouping in the templates.

func ToPagesGroup

func ToPagesGroup(seq any) (PagesGroup, bool, error)

ToPagesGroup tries to convert seq into a PagesGroup.

func (PagesGroup) Len

func (psg PagesGroup) Len() int

Len returns the number of pages in the page group.

func (PagesGroup) ProbablyEq

func (psg PagesGroup) ProbablyEq(other any) bool

ProbablyEq wraps compare.ProbablyEqer

func (PagesGroup) Reverse

func (p PagesGroup) Reverse() PagesGroup

Reverse reverses the order of this list of page groups.

type Paginator

type Paginator struct {
	// contains filtered or unexported fields
}

func Paginate

func Paginate(td TargetPathDescriptor, seq any, pagerSize int) (*Paginator, error)

func (*Paginator) PageSize

func (p *Paginator) PageSize() int

PageSize returns the size of each paginator page. Deprecated: Use PagerSize instead.

func (*Paginator) PagerSize added in v0.128.0

func (p *Paginator) PagerSize() int

PagerSize returns the size of each paginator page.

func (*Paginator) Pagers

func (p *Paginator) Pagers() pagers

Pagers returns a list of pagers that can be used to build a pagination menu.

func (*Paginator) TotalNumberOfElements

func (p *Paginator) TotalNumberOfElements() int

TotalNumberOfElements returns the number of elements on all pages in this paginator.

func (*Paginator) TotalPages

func (p *Paginator) TotalPages() int

TotalPages returns the number of pages in the paginator.

type PaginatorNotSupportedFunc added in v0.123.0

type PaginatorNotSupportedFunc func() error

func (PaginatorNotSupportedFunc) Paginate added in v0.123.0

func (f PaginatorNotSupportedFunc) Paginate(pages any, options ...any) (*Pager, error)

func (PaginatorNotSupportedFunc) Paginator added in v0.123.0

func (f PaginatorNotSupportedFunc) Paginator(options ...any) (*Pager, error)

type PaginatorProvider

type PaginatorProvider interface {
	// Paginator creates a paginator with the default page set.
	Paginator(options ...any) (*Pager, error)
	// Paginate creates a paginator with the given page set in pages.
	Paginate(pages any, options ...any) (*Pager, error)
}

PaginatorProvider provides two ways to create a page paginator.

type PermalinkExpander

type PermalinkExpander struct {
	// contains filtered or unexported fields
}

PermalinkExpander holds permalink mappings per section.

func NewPermalinkExpander

func NewPermalinkExpander(urlize func(uri string) string, patterns map[string]map[string]string) (PermalinkExpander, error)

NewPermalinkExpander creates a new PermalinkExpander configured by the given urlize func.

func (PermalinkExpander) Expand

func (l PermalinkExpander) Expand(key string, p Page) (string, error)

Expand expands the path in p according to the rules defined for the given key. If no rules are found for the given key, an empty string is returned.

type Positioner

type Positioner interface {
	// Next points up to the next regular page (sorted by Hugo’s default sort).
	Next() Page
	// Prev points down to the previous regular page (sorted by Hugo’s default sort).
	Prev() Page

	// Deprecated: Use Prev. Will be removed in Hugo 0.57
	PrevPage() Page

	// Deprecated: Use Next. Will be removed in Hugo 0.57
	NextPage() Page
}

Positioner provides next/prev navigation.

type RawContentProvider

type RawContentProvider interface {
	// RawContent returns the raw, unprocessed content of the page excluding any front matter.
	RawContent() string
}

RawContentProvider provides the raw, unprocessed content of the page.

type RefProvider

type RefProvider interface {
	// Ref returns an absolute URl to a page.
	Ref(argsm map[string]any) (string, error)

	// RefFrom is for internal use only.
	RefFrom(argsm map[string]any, source any) (string, error)

	// RelRef returns a relative URL to a page.
	RelRef(argsm map[string]any) (string, error)

	// RelRefFrom is for internal use only.
	RelRefFrom(argsm map[string]any, source any) (string, error)
}

RefProvider provides the methods needed to create reflinks to pages.

type RelatedDocsHandler

type RelatedDocsHandler struct {
	// contains filtered or unexported fields
}

func NewRelatedDocsHandler

func NewRelatedDocsHandler(cfg related.Config) *RelatedDocsHandler

func (*RelatedDocsHandler) Clone

type RelatedKeywordsProvider

type RelatedKeywordsProvider interface {
	// Make it indexable as a related.Document
	// RelatedKeywords is meant for internal usage only.
	RelatedKeywords(cfg related.IndexConfig) ([]related.Keyword, error)
}

RelatedKeywordsProvider allows a Page to be indexed.

type RenderShortcodesProvider added in v0.117.0

type RenderShortcodesProvider interface {
	// RenderShortcodes returns RawContent with any shortcodes rendered.
	RenderShortcodes(context.Context) (template.HTML, error)
}

type ShortcodeInfoProvider

type ShortcodeInfoProvider interface {
	// HasShortcode return whether the page has a shortcode with the given name.
	// This method is mainly motivated with the Hugo Docs site's need for a list
	// of pages with the `todo` shortcode in it.
	HasShortcode(name string) bool
}

ShortcodeInfoProvider provides info about the shortcodes in a Page.

type Site

type Site interface {
	// Returns the Language configured for this Site.
	Language() *langs.Language

	// Returns all the languages configured for all sites.
	Languages() langs.Languages

	GetPage(ref ...string) (Page, error)

	// AllPages returns all pages for all languages.
	AllPages() Pages

	// Returns all the regular Pages in this Site.
	RegularPages() Pages

	// Returns all Pages in this Site.
	Pages() Pages

	// Returns all the top level sections.
	Sections() Pages

	// A shortcut to the home
	Home() Page

	// Deprecated: Use hugo.IsServer instead.
	IsServer() bool

	// Returns the server port.
	ServerPort() int

	// Returns the configured title for this Site.
	Title() string

	// Deprecated: Use .Language.LanguageCode instead.
	LanguageCode() string

	// Returns the configured copyright information for this Site.
	Copyright() 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.HugoInfo

	// Returns the BaseURL for this Site.
	BaseURL() string

	// Returns a taxonomy map.
	Taxonomies() TaxonomyList

	// Deprecated: Use .Lastmod instead.
	LastChange() time.Time

	// Returns the last modification date of the content.
	Lastmod() time.Time

	// Returns the Menus for this site.
	Menus() navigation.Menus

	// The main sections in the site.
	MainSections() []string

	// Returns the Params configured for this site.
	Params() maps.Params

	// Param is a convenience method to do lookups in Params.
	Param(key any) (any, error)

	// Returns a map of all the data inside /data.
	Data() map[string]any

	// Returns the site config.
	Config() SiteConfig

	// Deprecated: Use taxonomies instead.
	Author() map[string]interface{}

	// Deprecated: Use taxonomies instead.
	Authors() AuthorList

	// Deprecated: Use .Site.Params instead.
	Social() map[string]string

	// Deprecated: Use Config().Services.GoogleAnalytics instead.
	GoogleAnalytics() string

	// Deprecated: Use Config().Privacy.Disqus instead.
	DisqusShortname() string

	// BuildDrafts is deprecated and will be removed in a future release.
	BuildDrafts() bool

	// Deprecated: Use hugo.IsMultilingual instead.
	IsMultiLingual() bool

	// LanguagePrefix returns the language prefix for this site.
	LanguagePrefix() string

	// Deprecated: Use .Site.Home.OutputFormats.Get "rss" instead.
	RSSLink() template.URL

	// For internal use only.
	// This will panic if the site is not fully initialized.
	// This is typically used to inform the user in the content adapter templates,
	// as these are executed before all the page collections etc. are ready to use.
	CheckReady()
}

Site represents a site. There can be multiple sites in a multilingual setup.

func NewDummyHugoSite added in v0.56.0

func NewDummyHugoSite(conf config.AllProvider) Site

NewDummyHugoSite creates a new minimal test site.

func WrapSite added in v0.112.0

func WrapSite(s Site) Site

type SiteConfig added in v0.112.0

type SiteConfig struct {
	// This contains all privacy related settings that can be used to
	// make the YouTube template etc. GDPR compliant.
	Privacy privacy.Config

	// Services contains config for services such as Google Analytics etc.
	Services services.Config
}

SiteConfig holds the config in site.Config.

type Sites

type Sites []Site

Sites represents an ordered list of sites (languages).

func (Sites) Default added in v0.126.3

func (s Sites) Default() Site

Default is a convenience method to get the site corresponding to the default content language.

func (Sites) First deprecated

func (s Sites) First() Site

Deprecated: Use .Sites.Default instead.

type SitesProvider

type SitesProvider interface {
	// Site returns the current site.
	Site() Site
	// Sites returns all sites.
	Sites() Sites
}

SitesProvider provide accessors to get sites.

type TableOfContentsProvider

type TableOfContentsProvider interface {
	// TableOfContents returns the table of contents for the page rendered as HTML.
	TableOfContents(context.Context) template.HTML

	// Fragments returns the fragments for this page.
	Fragments(context.Context) *tableofcontents.Fragments
}

TableOfContentsProvider provides the table of contents for a Page.

type TargetPathDescriptor

type TargetPathDescriptor struct {
	PathSpec *helpers.PathSpec

	Type output.Format
	Kind string

	Path    *paths.Path
	Section *paths.Path

	// For regular content pages this is either
	// 1) the Slug, if set,
	// 2) the file base name (TranslationBaseName).
	BaseName string

	// Typically a language prefix added to file paths.
	PrefixFilePath string

	// Typically a language prefix added to links.
	PrefixLink string

	// If in multihost mode etc., every link/path needs to be prefixed, even
	// if set in URL.
	ForcePrefix bool

	// URL from front matter if set. Will override any Slug etc.
	URL string

	// Used to create paginator links.
	Addends string

	// The expanded permalink if defined for the section, ready to use.
	ExpandedPermalink string

	// Some types cannot have uglyURLs, even if globally enabled, RSS being one example.
	UglyURLs bool
}

type TargetPaths

type TargetPaths struct {
	// Where to store the file on disk relative to the publish dir. OS slashes.
	TargetFilename string

	// The directory to write sub-resources of the above.
	SubResourceBaseTarget string

	// The base for creating links to sub-resources of the above.
	SubResourceBaseLink string

	// The relative permalink to this resources. Unix slashes.
	Link string
}

TODO(bep) move this type.

func CreateTargetPaths

func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths)

func (TargetPaths) PermalinkForOutputFormat

func (p TargetPaths) PermalinkForOutputFormat(s *helpers.PathSpec, f output.Format) string
func (p TargetPaths) RelPermalink(s *helpers.PathSpec) string

type Taxonomy added in v0.110.0

type Taxonomy map[string]WeightedPages

A Taxonomy is a map of keywords to a list of pages. For example

TagTaxonomy['technology'] = WeightedPages
TagTaxonomy['go']  =  WeightedPages

func (Taxonomy) Alphabetical added in v0.110.0

func (i Taxonomy) Alphabetical() OrderedTaxonomy

Alphabetical returns an ordered taxonomy sorted by key name.

func (Taxonomy) ByCount added in v0.110.0

func (i Taxonomy) ByCount() OrderedTaxonomy

ByCount returns an ordered taxonomy sorted by # of pages per key. If taxonomies have the same # of pages, sort them alphabetical

func (Taxonomy) Count added in v0.110.0

func (i Taxonomy) Count(key string) int

Count the weighted pages for the given key.

func (Taxonomy) Get added in v0.110.0

func (i Taxonomy) Get(key string) WeightedPages

Get the weighted pages for the given key.

func (Taxonomy) Page added in v0.125.0

func (i Taxonomy) Page() Page

Page returns the taxonomy page or nil if the taxonomy has no terms.

func (Taxonomy) TaxonomyArray added in v0.110.0

func (i Taxonomy) TaxonomyArray() OrderedTaxonomy

TaxonomyArray returns an ordered taxonomy with a non defined order.

type TaxonomyList added in v0.110.0

type TaxonomyList map[string]Taxonomy

The TaxonomyList is a list of all taxonomies and their values e.g. List['tags'] => TagTaxonomy (from above)

func (TaxonomyList) String added in v0.110.0

func (tl TaxonomyList) String() string

type TranslationsProvider

type TranslationsProvider interface {
	// IsTranslated returns whether this content file is translated to
	// other language(s).
	IsTranslated() bool

	// AllTranslations returns all translations, including the current Page.
	AllTranslations() Pages

	// Translations returns the translations excluding the current Page.
	Translations() Pages
}

TranslationsProvider provides access to any translations.

type TreeProvider

type TreeProvider interface {
	// 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.
	IsAncestor(other any) bool

	// CurrentSection returns the page's current section or the page itself if home or a section.
	// Note that this will return nil for pages that is not regular, home or section pages.
	CurrentSection() Page

	// IsDescendant returns whether the current page is a descendant of other.
	// Note that this method is not relevant for taxonomy lists and taxonomy terms pages.
	IsDescendant(other any) bool

	// FirstSection returns the section on level 1 below home, e.g. "/docs".
	// For the home page, this will return itself.
	FirstSection() Page

	// InSection returns whether other is in the current section.
	// Note that this will always return false for pages that are
	// not either regular, home or section pages.
	InSection(other any) bool

	// Parent returns a section's parent section or a page's section.
	// To get a section's subsections, see Page's Sections method.
	Parent() Page

	// Ancestors returns the ancestors of each page
	Ancestors() Pages

	// Sections returns this section's subsections, if any.
	// Note that for non-sections, this method will always return an empty list.
	Sections() Pages

	// Page returns a reference to the Page itself, kept here mostly
	// for legacy reasons.
	Page() Page

	// Returns a slice of sections (directories if it's a file) to this
	// Page.
	SectionsEntries() []string

	// SectionsPath is SectionsEntries joined with a /.
	SectionsPath() string
}

TreeProvider provides section tree navigation.

type WeightedPage

type WeightedPage struct {
	Weight int
	Page
	// contains filtered or unexported fields
}

A WeightedPage is a Page with a weight.

func NewWeightedPage

func NewWeightedPage(weight int, p Page, owner Page) WeightedPage

func (WeightedPage) Slice

func (p WeightedPage) Slice(in any) (any, error)

Slice is for internal use. for the template functions. See collections.Slice.

func (WeightedPage) String

func (w WeightedPage) String() string

type WeightedPages

type WeightedPages []WeightedPage

WeightedPages is a list of Pages with their corresponding (and relative) weight [{Weight: 30, Page: *1}, {Weight: 40, Page: *2}]

func (WeightedPages) Count

func (wp WeightedPages) Count() int

Count returns the number of pages in this weighted page set.

func (WeightedPages) Len

func (wp WeightedPages) Len() int

func (WeightedPages) Less

func (wp WeightedPages) Less(i, j int) bool

func (WeightedPages) Next

func (wp WeightedPages) Next(cur Page) Page

Next returns the next Page relative to the given Page in this weighted page set.

func (WeightedPages) Page

func (p WeightedPages) Page() Page

Page will return the Page (of Kind taxonomyList) that represents this set of pages. This method will panic if p is empty, as that should never happen.

func (WeightedPages) Pages

func (wp WeightedPages) Pages() Pages

Pages returns the Pages in this weighted page set.

func (WeightedPages) Prev

func (wp WeightedPages) Prev(cur Page) Page

Prev returns the previous Page relative to the given Page in this weighted page set.

func (WeightedPages) Sort

func (wp WeightedPages) Sort()

Sort stable sorts this weighted page set.

func (WeightedPages) Swap

func (wp WeightedPages) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL