Blog/Components/Pages/Git/GitBar.razor 2.1 K · 62 lines · raw · history

1 @* The one row of chrome a git page gets: where you are on the left, where else you can go on the
2 right. Inverted, like a terminal's status line — see git.css. *@
3
4 <nav class="git-bar">
5 <span class="git-crumbs">
6 <a href="/git">git</a>
7
8 @if (Repository is { Length: > 0 })
9 {
10 <span class="sep">/</span>
11 <a href="@RepoHref"><strong>@Repository</strong></a>
12
13 @foreach (var crumb in Path)
14 {
15 <span class="sep">/</span>
16 @if (crumb.Href is null)
17 {
18 <strong>@crumb.Name</strong>
19 }
20 else
21 {
22 <a href="@crumb.Href">@crumb.Name</a>
23 }
24 }
25 }
26 </span>
27
28 @if (Repository is { Length: > 0 })
29 {
30 <span class="git-tabs">
31 <a class="@Active("log")" href="@($"{RepoHref}/log{Query}")">log</a>
32 <a class="@Active("tree")" href="@($"{RepoHref}/tree{Query}")">tree</a>
33 <a class="@Active("refs")" href="@($"{RepoHref}/refs")">refs</a>
34 </span>
35 }
36 </nav>
37
38 @code {
39 /// <summary>One step of the path under the repository. A null href is the step you are on.</summary>
40 public sealed record Crumb(string Name, string? Href);
41
42 /// <summary>The repository's directory name. Empty on the index, which has no tabs.</summary>
43 [Parameter]
44 public string? Repository { get; set; }
45
46 /// <summary>Which tab to punch out: <c>log</c>, <c>tree</c> or <c>refs</c>.</summary>
47 [Parameter]
48 public string? Tab { get; set; }
49
50 /// <summary>The branch the tabs should stay on, when the page is on one.</summary>
51 [Parameter]
52 public string? Reference { get; set; }
53
54 [Parameter]
55 public IReadOnlyList<Crumb> Path { get; set; } = [];
56
57 private string RepoHref => $"/git/{Uri.EscapeDataString(Repository ?? "")}";
58
59 private string Query => string.IsNullOrEmpty(Reference) ? "" : $"?h={Uri.EscapeDataString(Reference)}";
60
61 private string? Active(string tab) => tab == Tab ? "on" : null;
62 }