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 if r := p.Release; r != nil {
119 <dt>release</dt>
120 <dd>
121 <a href={ templ.SafeURL(r.Href) }>{ r.Tag }</a>{ " · " }
122 <time datetime={ r.WhenAt } title={ r.WhenAt }>{ r.When }</time>{ " · " }
123 <a href={ templ.SafeURL(r.AllHref) }>all releases</a>
124 </dd>
125 }
126 </dl>
127 </section>
128 if len(p.Recent) > 0 {
129 <section aria-labelledby="r-recent"><h2 id="r-recent">Recent commits <a href={ templ.SafeURL(p.AllHref) }>View all</a></h2>@CommitRows(p.Recent)
130</section>
131 }
132 if p.Actions != nil {
133 @RecentActionsBlock(*p.Actions)
134 }
135 if len(p.Outline) > 0 && p.Readme != nil {
136 <section aria-labelledby="r-outline"><h2 id="r-outline">On this page</h2>@Outline(p.Outline)
137</section>
138 }
139}
140
141// Refs lists the branches and tags of a repository.
142templ Refs(l Layout, p RefsPage) {
143 @Shell(l, refsRail(p)) {
144 <div class="filter">
145 <label for="ref-filter" class="sr">filter</label>
146 <input
147 id="ref-filter"
148 type="search"
149 data-filter="#ref-rows > tr"
150 placeholder="Filter branches and tags…"
151 autocomplete="off"
152 hx-on:input="ermite.filter(this)"
153 />
154 </div>
155 <table class="list refs" aria-label="Branches and tags">
156 <thead>
157 <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>
158 </thead>
159 @RefsBody(p)
160 </table>
161 if p.Note != "" {
162 <p class="note">{ p.Note }</p>
163 }
164 }
165}
166
167templ refRow(kind string, r RefRow) {
168 <tr data-cursor?={ r.Cursor }>
169 <td class="c-kind mute">{ kind }</td>
170 <td class="c-name">
171 <a href={ templ.SafeURL(r.Href) }>{ r.Name }</a>
172 if r.Default {
173 <span class="pill">default</span>
174 }
175 </td>
176 <td class="c-sha">
177 if r.CHref != "" {
178 <a href={ templ.SafeURL(r.CHref) }>{ r.Short }</a>
179 } else {
180 { r.Short }
181 }
182 @CommitChecks(r.Checks)
183 </td>
184 <td class="c-sub">{ r.Subject }</td>
185 <td class="c-when dim">
186 if r.WhenAt != "" {
187 <time datetime={ r.WhenAt } title={ r.WhenAt }>{ r.When }</time>
188 }
189 </td>
190 </tr>
191}
192
193templ refsRail(p RefsPage) {
194 <section aria-labelledby="r-refs">
195 <h2 id="r-refs">Overview</h2>
196 @RefsKV(p)
197 </section>
198}
199
200// State is a 404, 500 or empty-repository page inside the normal shell.
201templ State(l Layout, p StatePage) {
202 @Shell(l, nil) {
203 <section class="state" aria-labelledby="state-title">
204 <p class="eyebrow">{ p.Code }</p>
205 <h1 id="state-title">{ p.Title }</h1>
206 for _, line := range p.Lines {
207 <p class="dim">{ line }</p>
208 }
209 if p.Clone != nil {
210 @CloneBlock(*p.Clone)
211 }
212 <p class="state-back">
213 for _, b := range p.Back {
214 <a href={ templ.SafeURL(b.Href) }>{ b.Label }</a>
215 }
216 </p>
217 </section>
218 }
219}
220
221// Login signs the browser in with a login link. Opening the link consumes
222// nothing; only this form does. ermite.js submits it as soon as a browser
223// shows the page (data-autosubmit): link previews and prefetchers run no
224// script, so they still cannot use the link. Without scripts the owner
225// clicks the button.
226templ Login(l Layout, p LoginPage) {
227 @Shell(l, nil) {
228 <section class="state" aria-labelledby="state-title">
229 <h1 id="state-title">{ p.Title }</h1>
230 for _, line := range p.Lines {
231 <p class="dim">{ line }</p>
232 }
233 <form class="state-act" method="post" action={ templ.SafeURL(p.Action) } data-autosubmit>
234 <button type="submit" class="btn primary">{ p.Button }</button>
235 </form>
236 <p class="state-back"><a href="/">Back to home</a></p>
237 </section>
238 }
239}
240
241// PasskeyLogin is the sign-in page: a button the script (passkey.js) drives.
242// Without script the button is hidden and the page says what to do instead.
243templ PasskeyLogin(l Layout, p PasskeyLoginPage) {
244 @Shell(l, nil) {
245 <section class="state" aria-labelledby="state-title">
246 <h1 id="state-title">{ p.Title }</h1>
247 <form class="state-act" data-js data-passkey-form>
248 <button type="submit" class="btn primary" data-passkey="login" data-begin={ p.Begin } data-finish={ p.Finish }>{ p.Button }</button>
249 </form>
250 <p class="dim" role="status" aria-live="polite" data-passkey-status></p>
251 for _, line := range p.Lines {
252 <p class="dim">{ line }</p>
253 }
254 <p class="state-back"><a href="/">Back to home</a></p>
255 </section>
256 }
257}
258
259// Passkeys lists the owner's passkeys, removes them and adds one.
260templ Passkeys(l Layout, p PasskeysPage) {
261 @Shell(l, nil) {
262 <h2 class="rule-h"><span>Passkeys</span><span class="count">{ itoa(len(p.Rows)) }</span></h2>
263 <p class="dim">A passkey signs you in from this device or your phone, without a terminal. Removing one signs every browser out.</p>
264 if len(p.Rows) > 0 {
265 <table class="list passkeys" aria-label="Passkeys">
266 <thead>
267 <tr>
268 <th class="c-name">Name</th>
269 <th class="c-when">Created</th>
270 <th class="c-when">Last used</th>
271 <th class="c-sync">Synced</th>
272 <th class="c-act"><span class="sr">Remove</span></th>
273 </tr>
274 </thead>
275 <tbody>
276 for _, r := range p.Rows {
277 <tr>
278 <td class="c-name">{ r.Name }</td>
279 <td class="c-when nowrap">
280 <time
281 if r.CreatedAt != "" {
282 datetime={ r.CreatedAt }
283 }
284 >{ r.Created }</time>
285 </td>
286 <td class="c-when nowrap">
287 <time
288 if r.LastUsedAt != "" {
289 datetime={ r.LastUsedAt }
290 }
291 >{ r.LastUsed }</time>
292 </td>
293 <td class="c-sync">
294 if r.Synced {
295 yes
296 } else {
297 no
298 }
299 </td>
300 <td class="c-act">
301 <form method="post" action={ templ.SafeURL(r.Remove) }>
302 <button type="submit" class="btn danger" aria-label={ "Remove passkey " + r.Name }>Remove</button>
303 </form>
304 </td>
305 </tr>
306 }
307 </tbody>
308 </table>
309 } else {
310 <p class="lede dim">no passkeys yet.</p>
311 }
312 if p.Full {
313 <p class="dim">{ itoa(p.Max) } passkeys are registered, the most there can be. Remove one to add another.</p>
314 } else {
315 <form class="passkey-add" data-js data-passkey-form>
316 <label for="passkey-name" class="sr">Name of the new passkey</label>
317 <input id="passkey-name" type="text" placeholder="Name, for example Pixel 9" autocomplete="off" data-passkey-name/>
318 <button type="submit" class="btn primary" data-passkey="register" data-begin={ p.Begin } data-finish={ p.Finish }>Add a passkey</button>
319 </form>
320 }
321 <p class="dim" role="status" aria-live="polite" data-passkey-status></p>
322 }
323}