Skip to content

Commit 7fa4cb8

Browse files
committed
update more places with hx-get and make append of querystring try to check for existing querystring
1 parent d8e286d commit 7fa4cb8

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Elastic.Documentation.Site/Htmx.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5+
using System.Reflection;
56
using System.Text;
7+
using Elastic.Documentation.Extensions;
68

79
namespace Elastic.Documentation.Site;
810

911
public static class Htmx
1012
{
13+
private static readonly string Version =
14+
Assembly.GetExecutingAssembly().GetCustomAttributes<AssemblyInformationalVersionAttribute>()
15+
.FirstOrDefault()?.InformationalVersion ?? "0.0.0";
16+
public static readonly string VersionHash = ShortId.Create(Version);
17+
1118
public static string GetHxSelectOob(bool hasSameTopLevelGroup) => hasSameTopLevelGroup ? "#content-container,#toc-nav" : "#main-container";
1219
public const string Preload = "mousedown";
1320
public const string HxSwap = "none";
@@ -24,6 +31,7 @@ public static string GetHxAttributes(
2431
string? hxIndicator = HxIndicator
2532
)
2633
{
34+
targetUrl = targetUrl.Contains('?') ? $"{targetUrl}&v={VersionHash}" : $"{targetUrl}?v={VersionHash}";
2735
var attributes = new StringBuilder();
2836
_ = attributes.Append($" hx-get={targetUrl}");
2937
_ = attributes.Append($" hx-select-oob={hxSwapOob ?? GetHxSelectOob(hasSameTopLevelGroup)}");

src/Elastic.Markdown/Myst/Renderers/HtmxLinkInlineRenderer.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ namespace Elastic.Markdown.Myst.Renderers;
1616

1717
public class HtmxLinkInlineRenderer : LinkInlineRenderer
1818
{
19-
private static readonly string Version =
20-
Assembly.GetExecutingAssembly().GetCustomAttributes<AssemblyInformationalVersionAttribute>()
21-
.FirstOrDefault()?.InformationalVersion ?? "0.0.0";
22-
private static readonly string VersionHash = ShortId.Create(Version);
23-
2419
protected override void Write(HtmlRenderer renderer, LinkInline link)
2520
{
2621
if (renderer.EnableHtmlForInline && !link.IsImage)
@@ -33,7 +28,8 @@ protected override void Write(HtmlRenderer renderer, LinkInline link)
3328
}
3429

3530
var url = link.GetDynamicUrl?.Invoke() ?? link.Url;
36-
url = $"{url}?v={VersionHash}";
31+
if (url is not null)
32+
url = url.Contains('?') ? $"{url}&v={Htmx.VersionHash}" : $"{url}?v={Htmx.VersionHash}";
3733

3834
var isCrossLink = (link.GetData("isCrossLink") as bool?) == true;
3935
var isHttpLink = url?.StartsWith("http") ?? false;

0 commit comments

Comments
 (0)