--- import { getDatabase, schema } from "@/db"; import BaseLayout from "@/layouts/BaseLayout.astro"; import { desc, eq, sql, count } from "drizzle-orm"; import { Compass, Search, BookMarked, Star, GitFork, ChevronLeft, ChevronRight, Plus } from "lucide-react"; 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: { columns: { id: true, username: true, avatarUrl: true, displayName: true }, }, }, limit: perPage, offset: offset, }); // Org-owned repos have a null `owner` relation — resolve org names in one pass const orgIds = repos .filter((r) => (r as any).ownerType === "organization") .map((r) => r.ownerId); const orgNameById = new Map(); if (orgIds.length > 0) { const orgs = await db.query.organizations.findMany({ where: (t, { inArray }) => inArray(t.id, orgIds), columns: { id: true, name: true }, }); for (const o of orgs) orgNameById.set(o.id, o.name); } 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`; if (seconds < 604800) return `${Math.floor(seconds / 86400)}d ago`; return `${Math.floor(seconds / 2592000)}mo ago`; } const langColors: Record = { JavaScript: "bg-[#f1e05a]", TypeScript: "bg-[#3178c6]", Python: "bg-[#3572A5]", Rust: "bg-[#dea584]", Go: "bg-[#00ADD8]", Java: "bg-[#b07219]", Ruby: "bg-[#701516]", "C++": "bg-[#f34b7d]", C: "bg-[#555555]", PHP: "bg-[#4F5D95]", HTML: "bg-[#e34c26]", CSS: "bg-[#563d7c]", Vue: "bg-[#41b883]", Astro: "bg-[#ff5a03]", Shell: "bg-[#89e051]", Dockerfile: "bg-[#384d54]", }; ---

Explore {totalCount > 0 && ( {totalCount} )}

Discover public repositories and open source projects from the community

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

No repositories found

Be the first to share your project with the OpenCodeHub community!

Create repository
) : ( )} {totalPages > 1 && (
{page > 1 && ( Previous )} Page {page} of {totalPages} {page < totalPages && ( Next )}
)}