hubolib: Add HasShortcode

Fixes #3707
This commit is contained in:
Bjørn Erik Pedersen 2017-07-17 23:20:13 +02:00
parent 00b590d7ab
commit deccc54004
2 changed files with 14 additions and 0 deletions

View file

@ -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

View file

@ -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