diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-08-01 18:12:36 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-08-03 20:00:57 +0200 |
commit | ade7ec818798c0e5507d4fb6cc5b4396262a85d6 (patch) | |
tree | fe1e2e18922b20286113d66e171dfecc861d30ff /resources | |
parent | 8fa8ce3e48c8812daa1eecc8865b653336d98147 (diff) |
Add Page.RenderShortcodes
A layouts/shortcodes/include.html shortcode may look like this:
```html
{{ $p := site.GetPage (.Get 0) }}
{{ $p.RenderShortcodes }}
```
Fixes #7297
Diffstat (limited to 'resources')
-rw-r--r-- | resources/page/page.go | 6 | ||||
-rw-r--r-- | resources/page/page_nop.go | 4 | ||||
-rw-r--r-- | resources/page/testhelpers_test.go | 136 |
3 files changed, 80 insertions, 66 deletions
diff --git a/resources/page/page.go b/resources/page/page.go index b1c867195..54fc71f33 100644 --- a/resources/page/page.go +++ b/resources/page/page.go @@ -277,6 +277,7 @@ type PageRenderProvider interface { // PageWithoutContent is the Page without any of the content methods. type PageWithoutContent interface { RawContentProvider + RenderShortcodesProvider resource.Resource PageMetaProvider resource.LanguageProvider @@ -362,6 +363,11 @@ type RawContentProvider interface { RawContent() string } +type RenderShortcodesProvider interface { + // RenderShortcodes returns RawContent with any shortcodes rendered. + RenderShortcodes(context.Context) (template.HTML, error) +} + // RefProvider provides the methods needed to create reflinks to pages. type RefProvider interface { // Ref returns an absolute URl to a page. diff --git a/resources/page/page_nop.go b/resources/page/page_nop.go index 59765ebf2..735d6eea8 100644 --- a/resources/page/page_nop.go +++ b/resources/page/page_nop.go @@ -401,6 +401,10 @@ func (p *nopPage) RawContent() string { return "" } +func (p *nopPage) RenderShortcodes(ctx context.Context) (template.HTML, error) { + return "", nil +} + func (p *nopPage) ReadingTime(context.Context) int { return 0 } diff --git a/resources/page/testhelpers_test.go b/resources/page/testhelpers_test.go index 50f297cab..ca2c4ff53 100644 --- a/resources/page/testhelpers_test.go +++ b/resources/page/testhelpers_test.go @@ -118,15 +118,15 @@ func (p *testPage) Err() resource.ResourceError { } func (p *testPage) Aliases() []string { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) AllTranslations() Pages { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) AlternativeOutputFormats() OutputFormats { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Author() Author { @@ -138,19 +138,19 @@ func (p *testPage) Authors() AuthorList { } func (p *testPage) BaseFileName() string { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) BundleType() files.ContentClass { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Content(context.Context) (any, error) { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) ContentBaseName() string { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) CurrentSection() Page { @@ -178,11 +178,11 @@ func (p *testPage) Description() string { } func (p *testPage) Dir() string { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Draft() bool { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Eq(other any) bool { @@ -194,11 +194,11 @@ func (p *testPage) ExpiryDate() time.Time { } func (p *testPage) Ext() string { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Extension() string { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) File() source.File { @@ -206,15 +206,15 @@ func (p *testPage) File() source.File { } func (p *testPage) FileInfo() hugofs.FileMetaInfo { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Filename() string { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) FirstSection() Page { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) FuzzyWordCount(context.Context) int { @@ -222,19 +222,19 @@ func (p *testPage) FuzzyWordCount(context.Context) int { } func (p *testPage) GetPage(ref string) (Page, error) { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) GetPageWithTemplateInfo(info tpl.Info, ref string) (Page, error) { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) GetParam(key string) any { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) GetTerms(taxonomy string) Pages { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) GetRelatedDocsHandler() *RelatedDocsHandler { @@ -250,27 +250,27 @@ func (p *testPage) CodeOwners() []string { } func (p *testPage) HasMenuCurrent(menuID string, me *navigation.MenuEntry) bool { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) HasShortcode(name string) bool { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Hugo() hugo.HugoInfo { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) InSection(other any) (bool, error) { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) IsAncestor(other any) (bool, error) { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) IsDescendant(other any) (bool, error) { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) IsDraft() bool { @@ -278,27 +278,27 @@ func (p *testPage) IsDraft() bool { } func (p *testPage) IsHome() bool { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) IsMenuCurrent(menuID string, inme *navigation.MenuEntry) bool { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) IsNode() bool { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) IsPage() bool { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) IsSection() bool { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) IsTranslated() bool { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Keywords() []string { @@ -314,7 +314,7 @@ func (p *testPage) Lang() string { } func (p *testPage) Language() *langs.Language { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) LanguagePrefix() string { @@ -348,11 +348,11 @@ func (p *testPage) LinkTitle() string { } func (p *testPage) LogicalName() string { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) MediaType() media.Type { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Menus() navigation.PageMenus { @@ -360,11 +360,11 @@ func (p *testPage) Menus() navigation.PageMenus { } func (p *testPage) Name() string { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Next() Page { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) NextInSection() Page { @@ -376,19 +376,19 @@ func (p *testPage) NextPage() Page { } func (p *testPage) OutputFormats() OutputFormats { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Pages() Pages { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) RegularPages() Pages { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) RegularPagesRecursive() Pages { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Paginate(seq any, options ...any) (*Pager, error) { @@ -412,11 +412,11 @@ func (p *testPage) Page() Page { } func (p *testPage) Parent() Page { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Ancestors() Pages { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Path() string { @@ -428,19 +428,19 @@ func (p *testPage) Pathc() string { } func (p *testPage) Permalink() string { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Plain(context.Context) string { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) PlainWords(context.Context) []string { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Prev() Page { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) PrevInSection() Page { @@ -460,15 +460,19 @@ func (p *testPage) RSSLink() template.URL { } func (p *testPage) RawContent() string { - panic("tespage: not implemented") + panic("testpage: not implemented") +} + +func (p *testPage) RenderShortcodes(context.Context) (template.HTML, error) { + panic("testpage: not implemented") } func (p *testPage) ReadingTime(context.Context) int { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Ref(argsm map[string]any) (string, error) { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) RefFrom(argsm map[string]any, source any) (string, error) { @@ -476,11 +480,11 @@ func (p *testPage) RefFrom(argsm map[string]any, source any) (string, error) { } func (p *testPage) RelPermalink() string { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) RelRef(argsm map[string]any) (string, error) { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) RelRefFrom(argsm map[string]any, source any) (string, error) { @@ -488,27 +492,27 @@ func (p *testPage) RelRefFrom(argsm map[string]any, source any) (string, error) } func (p *testPage) Render(ctx context.Context, layout ...string) (template.HTML, error) { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) RenderString(ctx context.Context, args ...any) (template.HTML, error) { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) ResourceType() string { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Resources() resource.Resources { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Scratch() *maps.Scratch { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Store() *maps.Scratch { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) RelatedKeywords(cfg related.IndexConfig) ([]related.Keyword, error) { @@ -525,7 +529,7 @@ func (p *testPage) Section() string { } func (p *testPage) Sections() Pages { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) SectionsEntries() []string { @@ -541,7 +545,7 @@ func (p *testPage) Site() Site { } func (p *testPage) Sites() Sites { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Slug() string { @@ -553,11 +557,11 @@ func (p *testPage) String() string { } func (p *testPage) Summary(context.Context) template.HTML { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) TableOfContents(context.Context) template.HTML { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Title() string { @@ -565,7 +569,7 @@ func (p *testPage) Title() string { } func (p *testPage) TranslationBaseName() string { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) TranslationKey() string { @@ -573,11 +577,11 @@ func (p *testPage) TranslationKey() string { } func (p *testPage) Translations() Pages { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Truncated(context.Context) bool { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Type() string { @@ -589,7 +593,7 @@ func (p *testPage) URL() string { } func (p *testPage) UniqueID() string { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) Weight() int { @@ -597,11 +601,11 @@ func (p *testPage) Weight() int { } func (p *testPage) WordCount(context.Context) int { - panic("tespage: not implemented") + panic("testpage: not implemented") } func (p *testPage) GetIdentity() identity.Identity { - panic("tespage: not implemented") + panic("testpage: not implemented") } func createTestPages(num int) Pages { |