diff options
Diffstat (limited to 'resources/page/page.go')
-rw-r--r-- | resources/page/page.go | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/resources/page/page.go b/resources/page/page.go index eeb2cdb28..00e716e83 100644 --- a/resources/page/page.go +++ b/resources/page/page.go @@ -16,10 +16,12 @@ package page import ( + "context" "html/template" "github.com/gohugoio/hugo/identity" "github.com/gohugoio/hugo/markup/converter" + "github.com/gohugoio/hugo/markup/tableofcontents" "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/tpl" @@ -76,40 +78,40 @@ type ChildCareProvider interface { // ContentProvider provides the content related values for a Page. type ContentProvider interface { - Content() (any, error) + Content(context.Context) (any, error) // Plain returns the Page Content stripped of HTML markup. - Plain() string + Plain(context.Context) string // PlainWords returns a string slice from splitting Plain using https://pkg.go.dev/strings#Fields. - PlainWords() []string + 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() template.HTML + Summary(context.Context) template.HTML // Truncated returns whether the Summary is truncated or not. - Truncated() bool + Truncated(context.Context) bool // FuzzyWordCount returns the approximate number of words in the content. - FuzzyWordCount() int + FuzzyWordCount(context.Context) int // WordCount returns the number of words in the content. - WordCount() int + WordCount(context.Context) int // ReadingTime returns the reading time based on the length of plain text. - ReadingTime() int + ReadingTime(context.Context) int // Len returns the length of the content. // This is for internal use only. - Len() int + Len(context.Context) int } // ContentRenderer provides the content rendering methods for some content. type ContentRenderer interface { // RenderContent renders the given content. // For internal use only. - RenderContent(content []byte, renderTOC bool) (converter.Result, error) + RenderContent(ctx context.Context, content []byte, renderTOC bool) (converter.Result, error) } // FileProvider provides the source file. @@ -167,6 +169,11 @@ type Page interface { PageWithoutContent } +type PageFragment interface { + resource.ResourceLinksProvider + resource.ResourceMetaProvider +} + // PageMetaProvider provides page metadata, typically provided via front matter. type PageMetaProvider interface { // The 4 page dates @@ -252,7 +259,7 @@ type PageMetaProvider interface { // PageRenderProvider provides a way for a Page to render content. type PageRenderProvider interface { // Render renders the given layout with this Page as context. - Render(layout ...string) (template.HTML, error) + 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: @@ -260,7 +267,7 @@ type PageRenderProvider interface { // 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(args ...any) (template.HTML, error) + RenderString(ctx context.Context, args ...any) (template.HTML, error) } // PageWithoutContent is the Page without any of the content methods. @@ -323,6 +330,14 @@ type PageWithoutContent interface { // Used in change/dependency tracking. identity.Provider + // Fragments returns the fragments for this page. + Fragments(context.Context) *tableofcontents.Fragments + + // Headings 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 + DeprecatedWarningPageMethods } @@ -387,7 +402,7 @@ type SitesProvider interface { // TableOfContentsProvider provides the table of contents for a Page. type TableOfContentsProvider interface { // TableOfContents returns the table of contents for the page rendered as HTML. - TableOfContents() template.HTML + TableOfContents(context.Context) template.HTML } // TranslationsProvider provides access to any translations. |