diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index 7e2d30f3..f3193f21 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -281,6 +281,11 @@ module Jekyll new_ary end + def sample(input) + return input unless input.respond_to?(:sample) + input.sample(1) + end + # Convert an object into its String representation for debugging # # input - The Object to be converted diff --git a/site/_docs/templates.md b/site/_docs/templates.md index 58e06c94..20a3a3f2 100644 --- a/site/_docs/templates.md +++ b/site/_docs/templates.md @@ -246,6 +246,17 @@ common tasks easier.
+Sample
+Pick a random value from an array.
+
+ {% raw %}{{ site.pages | sample }}{% endraw %}
+