detached 98d36bf

pages.templ RawHistoryFolder

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

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 2

Tags 45

↑↓ moveenter openesc close