Statiq.Web icon indicating copy to clipboard operation
Statiq.Web copied to clipboard

Question: Getting most recent dated posts?

Open hawkerm opened this issue 5 years ago • 2 comments

On my Jekyll site I had a sidebar which showed the 3 most recent posts on some pages.

I did this simply with {% for post in site.posts limit: 3 %}.

Documents seems to return everything, so I can't see how to filter it to just dated posts from the posts folder?

hawkerm avatar Apr 14 '19 05:04 hawkerm

Finally figured it out:

Documents["BlogPosts"].Take(3)

Though I'm not sure where I was supposed to figure out the argument for this filtering of the Documents? I happened to realize the Pipeline name and the connection after fumbling around the docs and having had a previous piece of Pipeline code to modify the locations of the posts to include the day in the folder structure.

hawkerm avatar Apr 14 '19 06:04 hawkerm

Glad you got it working. Part of the challenge here is probably the difference between Liquid (Jekyll’s templating language) and Razor (ASP.NET’s language and the one Wyam currently uses).

Liquid has special syntax and directives specifically for use in a template. Razor on the other hand mostly relies on standard C# and just provides ways to cut in and out (like the @ syntax). The .Take(3) method is from an API called LINQ that’s essentially part of C#. Documenting that gets challenging because where do you draw the line? Should every API in C# be documented? Should we document certain common use cases like taking a few documents, and if so, what are those use cases? That’s not to say the docs couldn’t be better, there’s always room for improvement there, just that it’s not totally straightforward what should be documented and how.

Some of this challenge (at least in this scenario) will hopefully go away soon. Wyam is designed from the ground up to be template language agnostic - it just happens that Razor was the first, and so far only, template language. I hope to get some other languages like Liquid and Mustache supported soon after the launch of v3. At that point you’ll be able to port themes from Jekyll much more directly.

daveaglick avatar Apr 14 '19 14:04 daveaglick