---
# site/index.md
title: Home
collection: /blog
---
<ul>
<% for (const post of (stati.collection?.recentPages ?? []).slice(0, 5)) { %>
<li>
<a href="<%= post.url %>"><%= post.frontMatter.title %></a>
<% if (post.publishedAt) { %>
<time datetime="<%= post.publishedAt.toISOString() %>"><%= post.publishedAt.toISOString().slice(0, 10) %></time>
<% } %>
</li>
<% } %>
</ul>
collection: /blog(orblog, or/blog/) gives any page the blog's collection. Without it, an index page reads its own folder's and every other page the one it sits in.- The entries are page models, not template data. The title is
post.frontMatter.title, as there's nopost.title, andpost.publishedAtis aDate, whilestati.page.publishedAtis the string from the front matter. recentPagesis newest first, and pages without a date come last. It includes every page under the folder, subfolders too.- Stati notes that the page read the collection, so a new, deleted or retitled post rebuilds the home page as well. A change to a post's body doesn't.
The posts read their own folder's collection, so prev/next links need no hook either:
<%
const posts = stati.collection?.recentPages ?? [];
const i = posts.findIndex((post) => post.url === stati.page.url);
const newer = i > 0 ? posts[i - 1] : undefined;
const older = i >= 0 ? posts[i + 1] : undefined;
%>
<% if (newer) { %><a href="<%= newer.url %>" rel="prev"><%= newer.frontMatter.title %></a><% } %>
<% if (older) { %><a href="<%= older.url %>" rel="next"><%= older.frontMatter.title %></a><% } %>
In the Stati docs: Which collection a page reads, Collection data and What rebuilds a listing.