I would like to use hexo such that I have a sidebar that appears on every page (a sidebar in layout.ejs) which has links to all my posts in reverse chronological order.
In my theme I have a sidebar.ejs snippet that looks like this:
<div class="sidebar-links-wrapper">
<% site.posts.each(function(item){ %>
<a href="<%- config.root %><%- item.path %>" class="navlink"><%- item.title %></a>
<% }); %>
</div>
But site.posts does not appear to be in the correct order. It doesn't show by order of the post creation date.
In index.ejs I have a section where the posts show up in the correct order (using page.posts).
<% page.posts.each(function(item){ %>
-- some other stuff
<% }); %>
However, I can't use page.posts in sidebar.ejs because layout.ejs includes sidebar.ejs and it appears to throw an error that page is not found if I reference the page variable.
Is there a way to correctly order site.posts? Or a way to reference page.posts from layout.ejs? Or a different way to achieve my desired effect?
Thank you for any help.