Add basic tag support for showing and filtering tagged posts

This commit is contained in:
2026-01-12 13:49:23 -08:00
parent b0fd1b6d9e
commit 88b6d1bade
7 changed files with 109 additions and 163 deletions

View File

@@ -3,12 +3,16 @@ import { getRecentPosts, formatDate, calculateReadTime, getNumOfPosts } from '..
import { parseTags } from '../../db/tags';
import { type BlogPost } from '../../db/queries';
export function Home({ searchParams }: { searchParams: Record<string, string> }) {
const currentPage = parseInt(searchParams.page || "1", 10);
export function Home({ searchParams }: { searchParams: URLSearchParams }) {
const postsPerPage = 10;
const totalPages = Math.ceil(getNumOfPosts() / postsPerPage);
const tags = searchParams.getAll('tag');
const currentPage = parseInt(searchParams.get('page') || "1", 10);
const totalPages = Math.ceil(getNumOfPosts(tags) / postsPerPage);
const offset = (currentPage - 1) * postsPerPage;
const posts = getRecentPosts(postsPerPage, offset); // Get posts for the current page
const posts = getRecentPosts(postsPerPage, offset, tags); // Get posts for the current page
return (
<main>