Skip to content

Commit d8e286d

Browse files
committed
add version number has to hx-get to break cache on version updates
1 parent 549ec4c commit d8e286d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
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;
6+
using Elastic.Documentation.Extensions;
57
using Elastic.Documentation.Site;
68
using Elastic.Documentation.Site.Navigation;
79
using Elastic.Markdown.IO;
@@ -14,6 +16,11 @@ namespace Elastic.Markdown.Myst.Renderers;
1416

1517
public class HtmxLinkInlineRenderer : LinkInlineRenderer
1618
{
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+
1724
protected override void Write(HtmlRenderer renderer, LinkInline link)
1825
{
1926
if (renderer.EnableHtmlForInline && !link.IsImage)
@@ -25,7 +32,8 @@ protected override void Write(HtmlRenderer renderer, LinkInline link)
2532
return;
2633
}
2734

28-
var url = link.GetDynamicUrl != null ? link.GetDynamicUrl() : link.Url;
35+
var url = link.GetDynamicUrl?.Invoke() ?? link.Url;
36+
url = $"{url}?v={VersionHash}";
2937

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

0 commit comments

Comments
 (0)