summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/page.go11
-rw-r--r--hugolib/site_output_test.go3
2 files changed, 14 insertions, 0 deletions
diff --git a/hugolib/page.go b/hugolib/page.go
index 0f44b8b99..9937be325 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -791,6 +791,17 @@ func (p *Page) Extension() string {
return p.extension
}
+// HasShortcode return whether the page has a shortcode with the given name.
+// This method is mainly motivated with the Hugo Docs site's need for a list
+// of pages with the `todo` shortcode in it.
+func (p *Page) HasShortcode(name string) bool {
+ if p.shortcodeState == nil {
+ return false
+ }
+
+ return p.shortcodeState.nameSet[name]
+}
+
// AllTranslations returns all translations, including the current Page.
func (p *Page) AllTranslations() Pages {
return p.translations
diff --git a/hugolib/site_output_test.go b/hugolib/site_output_test.go
index 8455a13f7..941387e35 100644
--- a/hugolib/site_output_test.go
+++ b/hugolib/site_output_test.go
@@ -254,6 +254,9 @@ Content: {{ .Content }}
require.Equal(t, "webcal://example.com/blog/index.ics", cal.Permalink())
}
+ require.True(t, home.HasShortcode("myShort"))
+ require.False(t, home.HasShortcode("doesNotExist"))
+
}
// Issue #3447