--- import { getDatabase, schema } from "@/db"; import BaseLayout from "@/layouts/BaseLayout.astro"; import { desc, eq, sql, count } from "drizzle-orm"; const db = getDatabase(); // Pagination const page = parseInt(Astro.url.searchParams.get("page") || "1"); const perPage = 12; const offset = (page - 1) * perPage; // Get total count let totalCount = 0; try { const [countResult] = await (db as any) .select({ count: count() }) .from(schema.repositories) .where(eq(schema.repositories.visibility, "public")); totalCount = countResult?.count || 0; } catch (e) {} const totalPages = Math.ceil(totalCount / perPage); // Fetch public repositories const repos = await db.query.repositories.findMany({ where: eq(schema.repositories.visibility, "public"), orderBy: [desc(schema.repositories.updatedAt)], with: { owner: true, }, limit: perPage, offset: offset, }); function timeAgo(date: string | Date) { const seconds = Math.floor( (new Date().getTime() - new Date(date).getTime()) / 1000, ); if (seconds < 60) return "just now"; if (seconds < 3600) return `${Math.floor(seconds / 60)}m ago`; if (seconds < 86400) return `${Math.floor(seconds / 3600)}h ago`; return `${Math.floor(seconds / 86400)}d ago`; } const langColors: Record = { JavaScript: "bg-yellow-400", TypeScript: "bg-blue-500", Python: "bg-green-500", Rust: "bg-orange-500", Go: "bg-cyan-400", Java: "bg-red-500", Ruby: "bg-red-600", "C++": "bg-pink-500", C: "bg-gray-500", PHP: "bg-purple-500", }; ---

Explore

Discover interesting repositories from the community

{ totalCount > 0 && (
Showing {offset + 1}-{Math.min(offset + perPage, totalCount)} of{" "} {totalCount} repositories
) } { repos.length === 0 ? (