import type { Hono } from "hono"; import { fileAt, headId, history, type Save, saveByPrefix } from "../mirror/queries.ts"; import { type Html, html } from "./html.ts"; import { cacheFor, notFound, openPublicRepo, type PageContext, type PublicRepo, page, relativeTime, } from "./layout.ts"; const RECENT = 20; export function registerArchivesPage(app: Hono, ctx: PageContext): void { app.get("/:repo/archives", (c) => { const repo = openPublicRepo(ctx, c.req.param("repo")); if (!repo) return notFound(c, ctx); const name = repo.settings.name; const id = headId(repo.mirror); const head = id ? saveByPrefix(repo.mirror, id) : null; const recent = history(repo.mirror, RECENT + 1, 0).filter((save) => save.id !== head?.id); cacheFor(c, false); return c.html( page(ctx, { title: `archives · ${name}`, description: `Source tarballs of ${name}, one per save.`, path: `/${name}/archives`, body: html`
no saves yet
` }${ isHead && html`HEAD` }${id}${html`${save.message.split("\n")[0]}`}${html`${relativeTime(save.created_at)}`}
↓ ${name}-${isHead ? "HEAD" : save.id.slice(0, 8)}.tar.gz
${ hasFlake && html`${nix}