diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index f3193f21..70e93b90 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -281,9 +281,9 @@ module Jekyll new_ary end - def sample(input) + def sample(input, num = 1) return input unless input.respond_to?(:sample) - input.sample(1) + input.sample(num) end # Convert an object into its String representation for debugging diff --git a/site/_docs/templates.md b/site/_docs/templates.md index 20a3a3f2..fd42b6b1 100644 --- a/site/_docs/templates.md +++ b/site/_docs/templates.md @@ -249,12 +249,15 @@ common tasks easier.
Sample
-Pick a random value from an array.
+Pick a random value from an array. Optional: pick multiple values.
{% raw %}{{ site.pages | sample }}{% endraw %}
+ {% raw %}{{ site.pages | sample:2 }}{% endraw %}
+