Skip to content

Commit

Permalink
hubolib: Add HasShortcode
Browse files Browse the repository at this point in the history
Fixes #3707
  • Loading branch information
bep committed Jul 17, 2017
1 parent 00b590d commit deccc54
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions hugolib/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions hugolib/site_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit deccc54

Please sign in to comment.