[backend/razor] Add CSS/JS versioning to razor pages & blazor ssr

This commit is contained in:
Laura Hausmann 2024-10-17 20:38:16 +02:00
parent 20f2168881
commit 4a5f575619
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
11 changed files with 56 additions and 24 deletions

View file

@ -1,5 +1,6 @@
@using Microsoft.AspNetCore.Components.Web @using Microsoft.AspNetCore.Components.Web
@using Iceshrimp.Backend.Components.Helpers
<HeadContent> <HeadContent>
<link rel="stylesheet" href="/css/admin.css"/> <VersionedLink rel="stylesheet" href="/css/admin.css"/>
<script src="/js/admin.js"></script> <VersionedScript src="/js/admin.js"/>
</HeadContent> </HeadContent>

View file

@ -0,0 +1,15 @@
@using Microsoft.AspNetCore.Mvc.ViewFeatures
<link @attributes="AdditionalAttributes" href="@VersionedHref"/>
@code {
[Inject] public required IFileVersionProvider FileVersionProvider { get; set; }
@* ReSharper disable InconsistentNaming *@
[Parameter, EditorRequired] public required string href { get; set; }
@* ReSharper restore InconsistentNaming *@
[Parameter(CaptureUnmatchedValues = true)]
public IDictionary<string, object>? AdditionalAttributes { get; set; }
private string VersionedHref => FileVersionProvider.AddFileVersionToPath("", href);
}

View file

@ -0,0 +1,15 @@
@using Microsoft.AspNetCore.Mvc.ViewFeatures
<script src="@VersionedSrc" @attributes="AdditionalAttributes"></script>
@code {
[Inject] public required IFileVersionProvider FileVersionProvider { get; set; }
@* ReSharper disable InconsistentNaming *@
[Parameter, EditorRequired] public required string src { get; set; }
@* ReSharper restore InconsistentNaming *@
[Parameter(CaptureUnmatchedValues = true)]
public IDictionary<string, object>? AdditionalAttributes { get; set; }
private string VersionedSrc => FileVersionProvider.AddFileVersionToPath("", src);
}

View file

@ -101,7 +101,7 @@ else
<meta name="og:image" content="@previewImageUrl"> <meta name="og:image" content="@previewImageUrl">
<meta name="og:description" content="@description"> <meta name="og:description" content="@description">
<link rel="stylesheet" href="/css/public-preview.css"/> <VersionedLink rel="stylesheet" href="/css/public-preview.css"/>
</HeadContent> </HeadContent>
if (!ShowRemoteReplies) if (!ShowRemoteReplies)

View file

@ -10,14 +10,14 @@
} }
@section head { @section head {
<link rel="stylesheet" href="~/css/queue.css"/> <link rel="stylesheet" href="~/css/queue.css" asp-append-version="true"/>
} }
@section scripts { @section scripts {
<script src="~/js/queue.js"></script> <script src="~/js/queue.js" asp-append-version="true"></script>
@if (Model.Queue == null) @if (Model.Queue == null)
{ {
<script src="~/js/queue-index.js"></script> <script src="~/js/queue-index.js" asp-append-version="true"></script>
} }
} }
@ -25,6 +25,7 @@
<button role="link" data-target="/queue" onclick="navigate(event)">overview</button> <button role="link" data-target="/queue" onclick="navigate(event)">overview</button>
@foreach (var queue in QueueSvc.QueueNames) @foreach (var queue in QueueSvc.QueueNames)
{ {
//asd
<button role="link" data-target="/queue/@queue" onclick="navigate(event)">@queue</button> <button role="link" data-target="/queue/@queue" onclick="navigate(event)">@queue</button>
} }
<br/> <br/>

View file

@ -11,11 +11,11 @@
} }
@section head { @section head {
<link rel="stylesheet" href="~/css/queue.css"/> <link rel="stylesheet" href="~/css/queue.css" asp-append-version="true"/>
} }
@section scripts { @section scripts {
<script src="~/js/queue.js"></script> <script src="~/js/queue.js" asp-append-version="true"></script>
} }
<h1>Queue Dashboard</h1> <h1>Queue Dashboard</h1>

View file

@ -15,10 +15,10 @@
<meta charset="utf-8"/> <meta charset="utf-8"/>
<title>@("Error - Iceshrimp.NET")</title> <title>@("Error - Iceshrimp.NET")</title>
@* ReSharper disable once Html.PathError *@ @* ReSharper disable once Html.PathError *@
<link rel="stylesheet" href="~/Iceshrimp.Backend.styles.css"/> <link rel="stylesheet" href="~/Iceshrimp.Backend.styles.css" asp-append-version="true"/>
<link rel="stylesheet" href="~/css/default.css"/> <link rel="stylesheet" href="~/css/default.css" asp-append-version="true"/>
@* ReSharper disable once Html.PathError *@ @* ReSharper disable once Html.PathError *@
<link rel="icon" type="image/png" href="~/favicon.png"/> <link rel="icon" type="image/png" href="~/favicon.png" asp-append-version="true"/>
<style> <style>
.float-right { .float-right {
float: right; float: right;

View file

@ -11,11 +11,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
<title>Iceshrimp.Frontend</title> <title>Iceshrimp.Frontend</title>
<base href="/"/> <base href="/"/>
<link rel="stylesheet" href="~/css/app.css"/> <link rel="stylesheet" href="~/css/app.css" asp-append-version="true"/>
<link rel="stylesheet" href="~/_content/Iceshrimp.Assets.PhosphorIcons/css/ph-regular.css"/> <link rel="stylesheet" href="~/_content/Iceshrimp.Assets.PhosphorIcons/css/ph-regular.css" asp-append-version="true"/>
<link rel="stylesheet" href="~/_content/Iceshrimp.Assets.PhosphorIcons/css/ph-fill.css"/> <link rel="stylesheet" href="~/_content/Iceshrimp.Assets.PhosphorIcons/css/ph-fill.css" asp-append-version="true"/>
<link rel="icon" type="image/png" href="~/favicon.png"/> <link rel="icon" type="image/png" href="~/favicon.png" asp-append-version="true"/>
<link href="~/Iceshrimp.Frontend.styles.css" rel="stylesheet"/> <link rel="stylesheet" href="~/Iceshrimp.Frontend.styles.css" asp-append-version="true"/>
</head> </head>
<body> <body>
@ -37,7 +37,7 @@
<a class="dismiss">🗙</a> <a class="dismiss">🗙</a>
</div> </div>
<script src="~/_framework/blazor.webassembly.js"></script> <script src="~/_framework/blazor.webassembly.js" asp-append-version="true"></script>
</body> </body>
</html> </html>

View file

@ -14,9 +14,9 @@
<!--suppress HtmlRequiredTitleElement, Justification: HeadOutlet --> <!--suppress HtmlRequiredTitleElement, Justification: HeadOutlet -->
<head> <head>
<meta charset="utf-8"/> <meta charset="utf-8"/>
<link rel="stylesheet" href="/Iceshrimp.Backend.styles.css"/> <VersionedLink rel="stylesheet" href="/Iceshrimp.Backend.styles.css"/>
<link rel="stylesheet" href="/css/default.css"/> <VersionedLink rel="stylesheet" href="/css/default.css"/>
<link rel="icon" type="image/png" href="/favicon.png"/> <VersionedLink rel="icon" type="image/png" href="/favicon.png"/>
<HeadOutlet/> <HeadOutlet/>
<PageTitle>@(_instanceName ?? "Iceshrimp.NET")</PageTitle> <PageTitle>@(_instanceName ?? "Iceshrimp.NET")</PageTitle>
</head> </head>

View file

@ -9,10 +9,10 @@
<meta charset="utf-8"/> <meta charset="utf-8"/>
<title>@(ViewData["title"] ?? "Iceshrimp.NET")</title> <title>@(ViewData["title"] ?? "Iceshrimp.NET")</title>
@* ReSharper disable once Html.PathError *@ @* ReSharper disable once Html.PathError *@
<link rel="stylesheet" href="~/Iceshrimp.Backend.styles.css"/> <link rel="stylesheet" href="~/Iceshrimp.Backend.styles.css" asp-append-version="true"/>
<link rel="stylesheet" href="~/css/default.css"/> <link rel="stylesheet" href="~/css/default.css" asp-append-version="true"/>
@* ReSharper disable once Html.PathError *@ @* ReSharper disable once Html.PathError *@
<link rel="icon" type="image/png" href="~/favicon.png"/> <link rel="icon" type="image/png" href="~/favicon.png" asp-append-version="true"/>
@await RenderSectionAsync("styles", false) @await RenderSectionAsync("styles", false)
@await RenderSectionAsync("head", false) @await RenderSectionAsync("head", false)
</head> </head>

View file

@ -36,6 +36,6 @@ else
<meta name="og:description" content="@bio"> <meta name="og:description" content="@bio">
} }
<meta name="og:image" content="@_user.AvatarUrl"> <meta name="og:image" content="@_user.AvatarUrl">
<link rel="stylesheet" href="/css/public-preview.css"/> <VersionedLink rel="stylesheet" href="/css/public-preview.css"/>
</HeadContent> </HeadContent>
} }