mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-31 22:41:53 +02:00
Add Page.Contents with scope support
Note that this also adds a new `.ContentWithoutSummary` method, and to do that we had to unify the different summary types: Both `auto` and `manual` now returns HTML. Before this commit, `auto` would return plain text. This could be considered to be a slightly breaking change, but for the better: Now you can treat the `.Summary` the same without thinking about where it comes from, and if you want plain text, pipe it into `{{ .Summary | plainify }}`. Fixes #8680 Fixes #12761 Fixes #12778 Fixes #716
This commit is contained in:
@@ -44,6 +44,8 @@ import (
|
||||
var (
|
||||
NopPage Page = new(nopPage)
|
||||
NopContentRenderer ContentRenderer = new(nopContentRenderer)
|
||||
NopMarkup Markup = new(nopMarkup)
|
||||
NopContent Content = new(nopContent)
|
||||
NopCPageContentRenderer = struct {
|
||||
OutputFormatPageContentProvider
|
||||
ContentRenderer
|
||||
@@ -109,10 +111,18 @@ func (p *nopPage) BundleType() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (p *nopPage) Markup(...any) Markup {
|
||||
return NopMarkup
|
||||
}
|
||||
|
||||
func (p *nopPage) Content(context.Context) (any, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (p *nopPage) ContentWithoutSummary(ctx context.Context) (template.HTML, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (p *nopPage) ContentBaseName() string {
|
||||
return ""
|
||||
}
|
||||
@@ -547,3 +557,69 @@ func (r *nopContentRenderer) ParseContent(ctx context.Context, content []byte) (
|
||||
func (r *nopContentRenderer) RenderContent(ctx context.Context, content []byte, doc any) (converter.ResultRender, bool, error) {
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
type (
|
||||
nopMarkup int
|
||||
nopContent int
|
||||
)
|
||||
|
||||
var (
|
||||
_ Markup = (*nopMarkup)(nil)
|
||||
_ Content = (*nopContent)(nil)
|
||||
)
|
||||
|
||||
func (c *nopMarkup) Render(context.Context) (Content, error) {
|
||||
return NopContent, nil
|
||||
}
|
||||
|
||||
func (c *nopMarkup) RenderString(ctx context.Context, args ...any) (template.HTML, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (c *nopMarkup) RenderShortcodes(context.Context) (template.HTML, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (c *nopContent) Plain(context.Context) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *nopContent) PlainWords(context.Context) []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *nopContent) WordCount(context.Context) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (c *nopContent) FuzzyWordCount(context.Context) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (c *nopContent) ReadingTime(context.Context) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (c *nopContent) Len(context.Context) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (c *nopContent) Content(context.Context) (template.HTML, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (c *nopContent) ContentWithoutSummary(context.Context) (template.HTML, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (c *nopMarkup) Fragments(context.Context) *tableofcontents.Fragments {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *nopMarkup) FragmentsHTML(context.Context) template.HTML {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *nopContent) Summary(context.Context) (Summary, error) {
|
||||
return Summary{}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user