summaryrefslogtreecommitdiffstats
path: root/hugolib/page.go
diff options
context:
space:
mode:
Diffstat (limited to 'hugolib/page.go')
-rw-r--r--hugolib/page.go48
1 files changed, 44 insertions, 4 deletions
diff --git a/hugolib/page.go b/hugolib/page.go
index 97f1ed351..40972d7c5 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -15,6 +15,7 @@ package hugolib
import (
"bytes"
+ "context"
"fmt"
"path"
"path/filepath"
@@ -24,8 +25,10 @@ import (
"go.uber.org/atomic"
"github.com/gohugoio/hugo/identity"
+ "github.com/gohugoio/hugo/related"
"github.com/gohugoio/hugo/markup/converter"
+ "github.com/gohugoio/hugo/markup/tableofcontents"
"github.com/gohugoio/hugo/tpl"
@@ -148,6 +151,43 @@ func (p *pageState) GetIdentity() identity.Identity {
return identity.NewPathIdentity(files.ComponentFolderContent, filepath.FromSlash(p.Pathc()))
}
+func (p *pageState) Fragments(ctx context.Context) *tableofcontents.Fragments {
+ p.s.initInit(ctx, p.cp.initToC, p)
+ if p.pageOutput.cp.tableOfContents == nil {
+ return tableofcontents.Empty
+ }
+ return p.pageOutput.cp.tableOfContents
+}
+
+func (p *pageState) HeadingsFiltered(context.Context) tableofcontents.Headings {
+ return nil
+}
+
+type pageHeadingsFiltered struct {
+ *pageState
+ headings tableofcontents.Headings
+}
+
+func (p *pageHeadingsFiltered) HeadingsFiltered(context.Context) tableofcontents.Headings {
+ return p.headings
+}
+
+func (p *pageHeadingsFiltered) page() page.Page {
+ return p.pageState
+}
+
+// For internal use by the related content feature.
+func (p *pageState) ApplyFilterToHeadings(ctx context.Context, fn func(*tableofcontents.Heading) bool) related.Document {
+ if p.pageOutput.cp.tableOfContents == nil {
+ return p
+ }
+ headings := p.pageOutput.cp.tableOfContents.Headings.FilterBy(fn)
+ return &pageHeadingsFiltered{
+ pageState: p,
+ headings: headings,
+ }
+}
+
func (p *pageState) GitInfo() source.GitInfo {
return p.gitInfo
}
@@ -351,7 +391,7 @@ func (p *pageState) String() string {
// IsTranslated returns whether this content file is translated to
// other language(s).
func (p *pageState) IsTranslated() bool {
- p.s.h.init.translations.Do()
+ p.s.h.init.translations.Do(context.Background())
return len(p.translations) > 0
}
@@ -375,13 +415,13 @@ func (p *pageState) TranslationKey() string {
// AllTranslations returns all translations, including the current Page.
func (p *pageState) AllTranslations() page.Pages {
- p.s.h.init.translations.Do()
+ p.s.h.init.translations.Do(context.Background())
return p.allTranslations
}
// Translations returns the translations excluding the current Page.
func (p *pageState) Translations() page.Pages {
- p.s.h.init.translations.Do()
+ p.s.h.init.translations.Do(context.Background())
return p.translations
}
@@ -461,7 +501,7 @@ func (p *pageState) initOutputFormat(isRenderingSite bool, idx int) error {
// Must be run after the site section tree etc. is built and ready.
func (p *pageState) initPage() error {
- if _, err := p.init.Do(); err != nil {
+ if _, err := p.init.Do(context.Background()); err != nil {
return err
}
return nil