Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

96 linesCodeBlameRaw
1/**
2 * A release as the Releases page and its own page show it: when and of
3 * which tag and commit on the left, its title, notes and downloads on the
4 * right; one above the other on a phone.
5 */
6import { FileArchive, GitCommitHorizontal, Tag as TagIcon } from "lucide-react";
7import { Link } from "react-router";
8
9import type { Release, RepoPath } from "@g1t/contracts";
10
11import { Markdown } from "./markdown";
12import { TimeAgo } from "./ui";
13import { Badge } from "./ui/badge";
14import { Card } from "./ui/card";
15import { UserCard } from "./user-card";
16
17export function encodeTag(tag: string): string {
18 return tag.split("/").map(encodeURIComponent).join("/");
19}
20
21export function ReleaseCard({ release, repo, linkTitle = true }: { release: Release; repo: RepoPath; linkTitle?: boolean }) {
22 const base = `/${repo.namespace}/${repo.name}`;
23 const title = release.name || release.tagName;
24 const when = release.publishedAt ?? release.createdAt;
25 return (
26 <article className="grid gap-4 md:grid-cols-[10rem_minmax(0,1fr)] md:gap-6">
27 <div className="flex flex-wrap items-center gap-x-4 gap-y-1.5 text-sm text-muted md:flex-col md:items-start md:pt-4">
28 <span className="text-faint">
29 <TimeAgo at={when} />
30 </span>
31 <Link
32 to={`${base}/tree/${encodeTag(release.tagName)}`}
33 className="inline-flex min-w-0 items-center gap-1.5 font-mono text-[0.8125rem] hover:text-accent"
34 >
35 <TagIcon size={14} className="shrink-0 text-faint" />
36 <span className="truncate">{release.tagName}</span>
37 </Link>
38 <Link to={`${base}/commit/${release.target}`} className="inline-flex items-center gap-1.5 font-mono text-[0.8125rem] hover:text-accent">
39 <GitCommitHorizontal size={14} className="shrink-0 text-faint" />
40 {release.target.slice(0, 7)}
41 </Link>
42 </div>
43 <Card className="min-w-0 overflow-hidden">
44 <div className="border-b border-line px-5 py-4">
45 <div className="flex flex-wrap items-center gap-2">
46 <h3 className="min-w-0 text-xl font-semibold tracking-tight wrap-break-word">
47 {linkTitle ? (
48 <Link to={`${base}/releases/tag/${encodeTag(release.tagName)}`} className="hover:text-accent hover:underline">
49 {title}
50 </Link>
51 ) : (
52 title
53 )}
54 </h3>
55 {release.latest && <Badge size="md">Latest</Badge>}
56 {release.prerelease && <Badge size="md">Pre-release</Badge>}
57 {release.draft && <Badge size="md">Draft</Badge>}
58 </div>
59 {release.author && (
60 <p className="mt-1 text-xs text-faint">
61 <UserCard username={release.author}>
62 <Link to={`/u/${release.author}`} className="font-medium text-muted hover:text-accent">
63 {release.author}
64 </Link>
65 </UserCard>{" "}
66 {release.draft ? "drafted this" : "released this"} <TimeAgo at={when} />
67 </p>
68 )}
69 </div>
70 <div className="px-5 py-4">
71 {release.body.trim() ? (
72 <Markdown
73 source={release.body}
74 repo={repo}
75 base={`${base}/blob/${encodeTag(release.tagName)}`}
76 rawBase={`${base}/raw/${encodeURIComponent(release.tagName)}`}
77 />
78 ) : (
79 <p className="text-sm text-faint">No notes.</p>
80 )}
81 </div>
82 <div className="border-t border-line px-5 py-3">
83 <h4 className="mb-2 text-xs font-medium tracking-wide text-faint uppercase">Downloads</h4>
84 <a
85 href={`${base}/archive/${encodeTag(release.tagName)}.zip`}
86 download
87 className="inline-flex items-center gap-2 text-sm text-muted hover:text-accent"
88 >
89 <FileArchive size={14} className="text-faint" />
90 Source code (zip)
91 </a>
92 </div>
93 </Card>
94 </article>
95 );
96}