- const sortedPosts = posts.sort((a, b) => b.timestamp - a.timestamp);
-
- const postsHTML = sortedPosts.length > 0
- ? `<h2>Recent Posts (${sortedPosts.length})</h2>` +
- sortedPosts.slice(0, 5).map((post) => {
- const excerpt = trimMD(post.content).slice(0, 100) +
- "...";
- return `
- <div class="post-item" onclick="window.location='/post/${post.id}'">
- <a href="/post/${post.id}" class="post-title">${
- escapeHTML(post.title)
- }</a>
- <div class="post-meta">
- <span>${new Date(post.timestamp).toLocaleDateString()}</span>
- </div>
- <div class="post-excerpt">${escapeHTML(excerpt)}</div>
- </div>
- `;
- }).join("")
- : '<div class="empty">No posts yet. Create your first post below!</div>';