New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate a random list of posts [Feature request] #1942
Comments
It might be a bit easier to understand for a user if we added a random template function that randomly selects elements from an array, map, or slice. To me, your recommendation makes me think they are randomly sorted, which I am not sure is a common use case or efficient processing wise. For instance, with a random function, we could have the following syntax and it will return a slice with a max of 5 items randomly selected from the input list.
The only con I see to this, is that it could appear as if your data on your page is changing regularly, so would need to keep that in mind w.r.t. SEO and how you use HTML5 elements. EDIT: Looks like on the master branch is a template function called |
Hello @christophermancini, @Jos512 Take a look at #1679. @christophermancini assumption is right. As the purpose of
This should satisfy you needs. |
Thanks for the responses Christopher and DigitalCraftsman. Look forward to using it in 0.16! 👍 |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I'd like to generate a random* list of post in Hugo; the idea is to place links to the first 5 of these below the posts as a way of "read more".
For this I was thinking about something like:
The idea is that Hugo, instead of generating a list ordered by date (
.Data.Pages.ByDate
), a list generates with all posts in.Data.Pages
ordered in a random manner. Then we can use the existingrange
,first
, andwhere
functions to "pull" the number of random posts from the list as we'd like.One requirement for this is that Hugo generates a random list of posts with a new seed each time
.Data.Pages.Random
is come across. Otherwise the list of posts will be random between builds, but not during builds.*: I know that such a list would be, theoretically speaking, pseudo-random. But I'm more than fine with a "seemingly random" list, especially since that would be easier to implement and is much friendlier on the build times.
(A related forum topic is here: https://discuss.gohugo.io/t/psuedo-random-list-of-category-posts/1923 ).
The text was updated successfully, but these errors were encountered: