1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package web
4
5import "fmt"
6
7// Home is the repository list.
8templ Home(l Layout, p HomePage) {
9 @Shell(l, nil) {
10 <h1 class="sr">Repositories</h1>
11 <div class="home" data-layout="cards">
12 <section class="home-repos" aria-label="Repositories">
13 <div class="home-bar">
14 <div class="filter">
15 <label for="home-filter" class="sr">filter</label>
16 <input
17 id="home-filter"
18 type="search"
19 data-filter="#repo-rows > li"
20 placeholder="Filter repositories…"
21 autocomplete="off"
22 hx-on:input="ermite.filter(this)"
23 />
24 </div>
25 <nav class="sort" aria-label="Sort repositories">
26 <span class="mute">sort</span>
27 for _, s := range p.Sorts {
28 <a
29 href={ templ.SafeURL(s.Href) }
30 if s.Mark != "" {
31 aria-current="true"
32 }
33 >
34 { s.Label }
35 if s.Mark != "" {
36 <span aria-hidden="true">{ s.Mark }</span>
37 <span class="sr">{ ", " + s.State }</span>
38 }
39 </a>
40 }
41 </nav>
42 <div class="layout-switch" role="group" aria-label="Layout" data-js>
43 <button type="button" class="btn icon" data-set-layout="cards" aria-pressed="true" title="Cards" aria-label="Cards">
44 <span class="ico i-cards" aria-hidden="true"></span>
45 </button>
46 <button type="button" class="btn icon" data-set-layout="split" aria-pressed="false" title="Two columns" aria-label="Two columns">
47 <span class="ico i-split" aria-hidden="true"></span>
48 </button>
49 <button type="button" class="btn icon" data-set-layout="compact" aria-pressed="false" title="Compact list" aria-label="Compact list">
50 <span class="ico i-compact" aria-hidden="true"></span>
51 </button>
52 </div>
53 </div>
54 <ul class="repos" id="repo-rows" data-rows data-sort={ p.Sort } data-desc={ fmt.Sprint(p.Desc) }>
55 for _, r := range p.Rows {
56 @HomeRowView(r)
57 }
58 </ul>
59 if len(p.Rows) == 0 {
60 <p class="lede dim">no repositories yet.</p>
61 }
62 </section>
63 </div>
64 }
65}
66
67// Summary is the summary of a repository: the README reads in the main
68// column at the reading measure; what one acts on sits in the rail.
69templ Summary(l Layout, p SummaryPage) {
70 @Shell(l, summaryRail(p)) {
71 if p.Readme != nil {
72 @ReadmeCard(*p.Readme)
73 }
74 }
75}
76
77// latestTagFact is the "latest tag" row of About: the newest tag (its
78// commit subject on hover), how old it is, and the count of tags, a link to
79// all of them. With too many tags to date them, the count only.
80templ latestTagFact(t LatestTag) {
81 <dt>latest tag</dt>
82 <dd class="latest-tag">
83 if t.Name != "" {
84 <a class="tag-name" href={ templ.SafeURL(t.Href) } title={ t.Subject }>{ t.Name }</a>
85 if t.WhenAt != "" {
86 { " · " }<time datetime={ t.WhenAt } title={ t.WhenAt }>{ t.When }</time>
87 }
88 { " · " }
89 }
90 <a class="all-tags" href={ templ.SafeURL(t.RefsHref) }>{ plural(t.Count, "tag", "tags") }</a>
91 </dd>
92}
93
94templ summaryRail(p SummaryPage) {
95 if p.Mirror != nil {
96 <section aria-labelledby="r-mirror">
97 <h2 id="r-mirror">Mirror</h2>
98 <p>⚠ Mirror { p.Mirror.State }</p>
99 if p.Mirror.Reason != "" {
100 <p>{ p.Mirror.Reason }</p>
101 }
102 <p>Run <code>{ p.Mirror.Command }</code></p>
103 </section>
104 }
105
106 <section aria-labelledby="r-clone"><h2 id="r-clone">Clone</h2>@CloneBlock(p.Clone)
107</section>
108 <section aria-labelledby="r-facts">
109 <h2 id="r-facts">About</h2>
110 <dl class="kv">
111 for _, f := range p.Facts {
112 <dt>{ f.Key }</dt>
113 @FactValue(f)
114 }
115 if p.Latest != nil {
116 @latestTagFact(*p.Latest)
117 }
118 </dl>
119 </section>
120 if len(p.Recent) > 0 {
121 <section aria-labelledby="r-recent"><h2 id="r-recent">Recent commits <a href={ templ.SafeURL(p.AllHref) }>View all</a></h2>@CommitRows(p.Recent)
122</section>
123 }
124 if p.Actions != nil {
125 @RecentActionsBlock(*p.Actions)
126 }
127 if len(p.Outline) > 0 && p.Readme != nil {
128 <section aria-labelledby="r-outline"><h2 id="r-outline">On this page</h2>@Outline(p.Outline)
129</section>
130 }
131}
132
133// Refs lists the branches and tags of a repository.
134templ Refs(l Layout, p RefsPage) {
135 @Shell(l, refsRail(p)) {
136 <div class="filter">
137 <label for="ref-filter" class="sr">filter</label>
138 <input
139 id="ref-filter"
140 type="search"
141 data-filter="#ref-rows > tr"
142 placeholder="Filter branches and tags…"
143 autocomplete="off"
144 hx-on:input="ermite.filter(this)"
145 />
146 </div>
147 <table class="list refs" aria-label="Branches and tags">
148 <thead>
149 <tr><th class="c-kind">kind</th><th class="c-name">name</th><th class="c-sha">commit</th><th class="c-sub">subject</th><th class="c-when">date</th></tr>
150 </thead>
151 @RefsBody(p)
152 </table>
153 if p.Note != "" {
154 <p class="note">{ p.Note }</p>
155 }
156 }
157}
158
159templ refRow(kind string, r RefRow) {
160 <tr data-cursor?={ r.Cursor }>
161 <td class="c-kind mute">{ kind }</td>
162 <td class="c-name">
163 <a href={ templ.SafeURL(r.Href) }>{ r.Name }</a>
164 if r.Default {
165 <span class="pill">default</span>
166 }
167 </td>
168 <td class="c-sha">
169 if r.CHref != "" {
170 <a href={ templ.SafeURL(r.CHref) }>{ r.Short }</a>
171 } else {
172 { r.Short }
173 }
174 @CommitChecks(r.Checks)
175 </td>
176 <td class="c-sub">{ r.Subject }</td>
177 <td class="c-when dim">
178 if r.WhenAt != "" {
179 <time datetime={ r.WhenAt } title={ r.WhenAt }>{ r.When }</time>
180 }
181 </td>
182 </tr>
183}
184
185templ refsRail(p RefsPage) {
186 <section aria-labelledby="r-refs">
187 <h2 id="r-refs">Overview</h2>
188 @RefsKV(p)
189 </section>
190}
191
192// State is a 404, 500 or empty-repository page inside the normal shell.
193templ State(l Layout, p StatePage) {
194 @Shell(l, nil) {
195 <section class="state" aria-labelledby="state-title">
196 <p class="eyebrow">{ p.Code }</p>
197 <h1 id="state-title">{ p.Title }</h1>
198 for _, line := range p.Lines {
199 <p class="dim">{ line }</p>
200 }
201 if p.Clone != nil {
202 @CloneBlock(*p.Clone)
203 }
204 <p class="state-back">
205 for _, b := range p.Back {
206 <a href={ templ.SafeURL(b.Href) }>{ b.Label }</a>
207 }
208 </p>
209 </section>
210 }
211}
212
213// Login signs the browser in with a login link. Opening the link consumes
214// nothing; only this form does. ermite.js submits it as soon as a browser
215// shows the page (data-autosubmit): link previews and prefetchers run no
216// script, so they still cannot use the link. Without scripts the owner
217// clicks the button.
218templ Login(l Layout, p LoginPage) {
219 @Shell(l, nil) {
220 <section class="state" aria-labelledby="state-title">
221 <h1 id="state-title">{ p.Title }</h1>
222 for _, line := range p.Lines {
223 <p class="dim">{ line }</p>
224 }
225 <form class="state-act" method="post" action={ templ.SafeURL(p.Action) } data-autosubmit>
226 <button type="submit" class="btn primary">{ p.Button }</button>
227 </form>
228 <p class="state-back"><a href="/">Back to home</a></p>
229 </section>
230 }
231}
232
233// PasskeyLogin is the sign-in page: a button the script (passkey.js) drives.
234// Without script the button is hidden and the page says what to do instead.
235templ PasskeyLogin(l Layout, p PasskeyLoginPage) {
236 @Shell(l, nil) {
237 <section class="state" aria-labelledby="state-title">
238 <h1 id="state-title">{ p.Title }</h1>
239 <form class="state-act" data-js data-passkey-form>
240 <button type="submit" class="btn primary" data-passkey="login" data-begin={ p.Begin } data-finish={ p.Finish }>{ p.Button }</button>
241 </form>
242 <p class="dim" role="status" aria-live="polite" data-passkey-status></p>
243 for _, line := range p.Lines {
244 <p class="dim">{ line }</p>
245 }
246 <p class="state-back"><a href="/">Back to home</a></p>
247 </section>
248 }
249}
250
251// Passkeys lists the owner's passkeys, removes them and adds one.
252templ Passkeys(l Layout, p PasskeysPage) {
253 @Shell(l, nil) {
254 <h2 class="rule-h"><span>Passkeys</span><span class="count">{ itoa(len(p.Rows)) }</span></h2>
255 <p class="dim">A passkey signs you in from this device or your phone, without a terminal. Removing one signs every browser out.</p>
256 if len(p.Rows) > 0 {
257 <table class="list passkeys" aria-label="Passkeys">
258 <thead>
259 <tr>
260 <th class="c-name">Name</th>
261 <th class="c-when">Created</th>
262 <th class="c-when">Last used</th>
263 <th class="c-sync">Synced</th>
264 <th class="c-act"><span class="sr">Remove</span></th>
265 </tr>
266 </thead>
267 <tbody>
268 for _, r := range p.Rows {
269 <tr>
270 <td class="c-name">{ r.Name }</td>
271 <td class="c-when nowrap">
272 <time
273 if r.CreatedAt != "" {
274 datetime={ r.CreatedAt }
275 }
276 >{ r.Created }</time>
277 </td>
278 <td class="c-when nowrap">
279 <time
280 if r.LastUsedAt != "" {
281 datetime={ r.LastUsedAt }
282 }
283 >{ r.LastUsed }</time>
284 </td>
285 <td class="c-sync">
286 if r.Synced {
287 yes
288 } else {
289 no
290 }
291 </td>
292 <td class="c-act">
293 <form method="post" action={ templ.SafeURL(r.Remove) }>
294 <button type="submit" class="btn danger" aria-label={ "Remove passkey " + r.Name }>Remove</button>
295 </form>
296 </td>
297 </tr>
298 }
299 </tbody>
300 </table>
301 } else {
302 <p class="lede dim">no passkeys yet.</p>
303 }
304 if p.Full {
305 <p class="dim">{ itoa(p.Max) } passkeys are registered, the most there can be. Remove one to add another.</p>
306 } else {
307 <form class="passkey-add" data-js data-passkey-form>
308 <label for="passkey-name" class="sr">Name of the new passkey</label>
309 <input id="passkey-name" type="text" placeholder="Name, for example Pixel 9" autocomplete="off" data-passkey-name/>
310 <button type="submit" class="btn primary" data-passkey="register" data-begin={ p.Begin } data-finish={ p.Finish }>Add a passkey</button>
311 </form>
312 }
313 <p class="dim" role="status" aria-live="polite" data-passkey-status></p>
314 }
315}