Forge

Jessie / forge public

Self-hosted git - made by qwen 3.8 27b

commit: 0c9688e9

Branches

main
MainLayout.razor 5.4 kB · 130 lines RawHistory
@inherits LayoutComponentBase
@using Microsoft.AspNetCore.Diagnostics
@inject CurrentUser Me
@inject IHttpContextAccessor Http

<a class="skip-link" href="#main">@T["Skip to content"]</a>

<header class="topbar">
    <div class="wrap topbar-inner">
        <a class="brand" href="/">
            <Icon Name="logo" Size="22" Class="logo-mark"/>
            <span>Forge</span>
        </a>

        <form class="search" method="get" action="/" role="search">
            <Icon Name="search" Size="15"/>
            <input type="search" name="q" value="@Query" placeholder="@T["Search repositories"]"
                   aria-label="@T["Search repositories"]" autocomplete="off" data-hotkey="/"/>
            <kbd class="js-only">/</kbd>
        </form>

        <nav class="topnav">
            <button type="button" class="icon-button js-only" data-theme-toggle
                    title="@T["Switch theme"]" aria-label="@T["Switch theme"]">
                <Icon Name="monitor" Size="17" Class="theme-icon theme-icon-auto"/>
                <Icon Name="sun" Size="17" Class="theme-icon theme-icon-light"/>
                <Icon Name="moon" Size="17" Class="theme-icon theme-icon-dark"/>
            </button>
            @if (Me.IsAuthenticated)
            {
                <a class="icon-button" href="/new" title="@T["New repository"]" aria-label="@T["New repository"]">
                    <Icon Name="plus" Size="18"/>
                </a>
                <details class="menu">
                    <summary class="menu-button" aria-label="@T["Account menu"]">
                        <Avatar Name="@(Me.Username ?? "")" Size="md"/>
                        <Icon Name="chevron-down" Size="14"/>
                    </summary>
                    <div class="menu-panel menu-right">
                        <p class="menu-header">@T["Signed in as"] <strong>@Me.Username</strong></p>
                        <a class="menu-item" href="@Urls.User(Me.Username!)"><Icon Name="book"/> @T["Your repositories"]</a>
                        <a class="menu-item" href="/new"><Icon Name="plus"/> @T["New repository"]</a>
                        <a class="menu-item" href="/settings/tokens"><Icon Name="key"/> @T["Access tokens"]</a>
                        <form method="post" action="/logout" class="menu-form">
                            <AntiforgeryToken/>
                            <button type="submit" class="menu-item"><Icon Name="sign-out"/> @T["Sign out ({0})", Me.Username]</button>
                        </form>
                    </div>
                </details>
            }
            else
            {
                <a class="button small" href="/login">@T["Sign in"]</a>
            }
        </nav>
    </div>
</header>

<main class="wrap" id="main">
    @Body
</main>

<footer class="footer">
    <div class="wrap footer-inner">
        <span class="footer-brand muted">
            <Icon Name="logo" Size="15" Class="logo-mark"/>
            Forge · @T["self-hosted Git"]
            <button type="button" class="link-button js-only footer-link" data-open-dialog="shortcuts">@T["Keyboard shortcuts"]</button>
        </span>
        <form method="post" action="/language" class="language-form">
            <AntiforgeryToken/>
            <input type="hidden" name="returnUrl" value="@ReturnUrl"/>
            <span class="muted language-label"><Icon Name="globe" Size="14"/> @T["Language"]:</span>
            @foreach (var language in T.Languages)
            {
                var name = CultureInfo.GetCultureInfo(language).NativeName;
                @if (string.Equals(language, T.Language, StringComparison.OrdinalIgnoreCase))
                {
                    <strong lang="@language">@name</strong>
                }
                else
                {
                    <button type="submit" name="lang" value="@language" lang="@language" class="link-button">@name</button>
                }
            }
        </form>
    </div>
</footer>

@* Opened by the "?" key or the footer link (app.js). *@
<dialog class="dialog" id="shortcuts" aria-labelledby="shortcuts-title">
    <h2 id="shortcuts-title">@T["Keyboard shortcuts"]</h2>
    <dl class="shortcut-list">
        <dt><kbd>/</kbd></dt>
        <dd>@T["Search repositories"]</dd>
        <dt><kbd>s</kbd></dt>
        <dd>@T["Search file names and code"]</dd>
        <dt><kbd>y</kbd></dt>
        <dd>@T["Open the permalink of the file being viewed"]</dd>
        <dt><kbd>?</kbd></dt>
        <dd>@T["Show this help"]</dd>
    </dl>
    <form method="dialog">
        <button type="submit" class="button">@T["Close"]</button>
    </form>
</dialog>

@code {
    /// <summary>The search box keeps what was searched for on the repository list.</summary>
    private string? Query =>
        Http.HttpContext is { } context && context.Request.Path == "/" ? context.Request.Query["q"].ToString() : null;

    /// <summary>Where the language switcher returns to: the page the visitor asked for, even when an error page is shown instead.</summary>
    private string ReturnUrl
    {
        get
        {
            var context = Http.HttpContext;
            if (context is null)
            {
                return "/";
            }

            var original = context.Features.Get<IStatusCodeReExecuteFeature>();
            return original is not null
                ? original.OriginalPathBase + original.OriginalPath + original.OriginalQueryString
                : context.Request.PathBase + context.Request.Path + context.Request.QueryString;
        }
    }
}

Keyboard shortcuts

/
Search repositories
s
Search file names and code
y
Open the permalink of the file being viewed
?
Show this help