diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-02-11 16:20:24 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-02-21 17:56:41 +0100 |
commit | 90da7664bf1f3a0ca2e18144b5deacf532c6e3cf (patch) | |
tree | 78d8ac72ebb2ccee4ca4bbeeb9add3365c743e90 /resources/page/page_nop.go | |
parent | 0afec0a9f4aace1f5f4af6822aeda6223ee3e3a9 (diff) |
Add page fragments support to Related
The main topic of this commit is that you can now index fragments (content heading identifiers) when calling `.Related`.
You can do this by:
* Configure one or more indices with type `fragments`
* The name of those index configurations maps to an (optional) front matter slice with fragment references. This allows you to link
page<->fragment and page<->page.
* This also will index all the fragments (heading identifiers) of the pages.
It's also possible to use type `fragments` indices in shortcode, e.g.:
```
{{ $related := site.RegularPages.Related .Page }}
```
But, and this is important, you need to include the shortcode using the `{{<` delimiter. Not doing so will create infinite loops and timeouts.
This commit also:
* Adds two new methods to Page: Fragments (can also be used to build ToC) and HeadingsFiltered (this is only used in Related Content with
index type `fragments` and `enableFilter` set to true.
* Consolidates all `.Related*` methods into one, which takes either a `Page` or an options map as its only argument.
* Add `context.Context` to all of the content related Page API. Turns out it wasn't strictly needed for this particular feature, but it will
soon become usefil, e.g. in #9339.
Closes #10711
Updates #9339
Updates #10725
Diffstat (limited to 'resources/page/page_nop.go')
-rw-r--r-- | resources/page/page_nop.go | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/resources/page/page_nop.go b/resources/page/page_nop.go index c4af3f554..8946926a2 100644 --- a/resources/page/page_nop.go +++ b/resources/page/page_nop.go @@ -17,11 +17,13 @@ package page import ( "bytes" + "context" "html/template" "time" "github.com/gohugoio/hugo/identity" "github.com/gohugoio/hugo/markup/converter" + "github.com/gohugoio/hugo/markup/tableofcontents" "github.com/gohugoio/hugo/hugofs/files" "github.com/gohugoio/hugo/tpl" @@ -105,7 +107,7 @@ func (p *nopPage) BundleType() files.ContentClass { return "" } -func (p *nopPage) Content() (any, error) { +func (p *nopPage) Content(context.Context) (any, error) { return "", nil } @@ -179,7 +181,7 @@ func (p *nopPage) FirstSection() Page { return nil } -func (p *nopPage) FuzzyWordCount() int { +func (p *nopPage) FuzzyWordCount(context.Context) int { return 0 } @@ -279,7 +281,7 @@ func (p *nopPage) Lastmod() (t time.Time) { return } -func (p *nopPage) Len() int { +func (p *nopPage) Len(context.Context) int { return 0 } @@ -363,11 +365,11 @@ func (p *nopPage) Permalink() string { return "" } -func (p *nopPage) Plain() string { +func (p *nopPage) Plain(context.Context) string { return "" } -func (p *nopPage) PlainWords() []string { +func (p *nopPage) PlainWords(context.Context) []string { return nil } @@ -399,7 +401,7 @@ func (p *nopPage) RawContent() string { return "" } -func (p *nopPage) ReadingTime() int { +func (p *nopPage) ReadingTime(context.Context) int { return 0 } @@ -415,11 +417,11 @@ func (p *nopPage) RelRef(argsm map[string]any) (string, error) { return "", nil } -func (p *nopPage) Render(layout ...string) (template.HTML, error) { +func (p *nopPage) Render(ctx context.Context, layout ...string) (template.HTML, error) { return "", nil } -func (p *nopPage) RenderString(args ...any) (template.HTML, error) { +func (p *nopPage) RenderString(ctx context.Context, args ...any) (template.HTML, error) { return "", nil } @@ -475,11 +477,11 @@ func (p *nopPage) String() string { return "nopPage" } -func (p *nopPage) Summary() template.HTML { +func (p *nopPage) Summary(context.Context) template.HTML { return "" } -func (p *nopPage) TableOfContents() template.HTML { +func (p *nopPage) TableOfContents(context.Context) template.HTML { return "" } @@ -499,7 +501,7 @@ func (p *nopPage) Translations() Pages { return nil } -func (p *nopPage) Truncated() bool { +func (p *nopPage) Truncated(context.Context) bool { return false } @@ -519,7 +521,7 @@ func (p *nopPage) Weight() int { return 0 } -func (p *nopPage) WordCount() int { +func (p *nopPage) WordCount(context.Context) int { return 0 } @@ -527,9 +529,16 @@ func (p *nopPage) GetIdentity() identity.Identity { return identity.NewPathIdentity("content", "foo/bar.md") } +func (p *nopPage) Fragments(context.Context) *tableofcontents.Fragments { + return nil +} +func (p *nopPage) HeadingsFiltered(context.Context) tableofcontents.Headings { + return nil +} + type nopContentRenderer int -func (r *nopContentRenderer) RenderContent(content []byte, renderTOC bool) (converter.Result, error) { +func (r *nopContentRenderer) RenderContent(ctx context.Context, content []byte, renderTOC bool) (converter.Result, error) { b := &bytes.Buffer{} return b, nil } |