shithub: hugo

Download patch

ref: deccc54004cbe88ddbf8f3f951d3178dc0693189
parent: 00b590d7ab4f3021814acceaf74c4eaf64edb226
author: Bjørn Erik Pedersen <[email protected]>
date: Mon Jul 17 19:20:13 EDT 2017

hubolib: Add HasShortcode

Fixes #3707

--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -791,6 +791,17 @@
 	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
--- a/hugolib/site_output_test.go
+++ b/hugolib/site_output_test.go
@@ -254,6 +254,9 @@
 		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