import type { Context } from "hono";
import { newestSaves, type RepoStats, repoStats, type Save } from "../mirror/queries.ts";
import { repoNames } from "../server/db.ts";
import { signedIn } from "../server/login.ts";
import { type Html, html } from "./html.ts";
import { openRepo, type PageContext, type PublicRepo, plural } from "./layout.ts";
import { repoIntro } from "./repo.ts";
export type LibraryRepo = PublicRepo & { stats: RepoStats; description: string };
export type RecentSave = { repo: string; save: Save };
export function libraryRepos(ctx: PageContext, visibility: 0 | 1 = 1): LibraryRepo[] {
return repoNames(ctx.kepr, visibility).flatMap((name) => {
const repo = openRepo(ctx, name, visibility);
if (!repo) return [];
const description = repoIntro(repo)?.text ?? "";
return [{ ...repo, stats: repoStats(repo.mirror), description }];
});
}
export function privateRepoCards(c: Context, ctx: PageContext): Html | null {
c.header("Vary", "Cookie", { append: true });
if (!signedIn(ctx, c)) return null;
c.header("Cache-Control", "no-store");
const repos = libraryRepos(ctx, 0);
return repos.length
? html`private repos
${repoCards(repos)}
${repo.description}
`} ${category && html`${category}
`} `; }