diff --git a/src/Elastic.ApiExplorer/ApiViewModel.cs b/src/Elastic.ApiExplorer/ApiViewModel.cs index 4d53d79d9..472f59891 100644 --- a/src/Elastic.ApiExplorer/ApiViewModel.cs +++ b/src/Elastic.ApiExplorer/ApiViewModel.cs @@ -29,6 +29,7 @@ public HtmlString RenderMarkdown(string? markdown) => public GlobalLayoutViewModel CreateGlobalLayoutModel() => new() { + DocsBuilderVersion = "0.0.0", // TODO: Use a version from the docs-builder DocSetName = "Api Explorer", Description = "", CurrentNavigationItem = CurrentNavigationItem, diff --git a/src/Elastic.Documentation.Site/Assets/main.ts b/src/Elastic.Documentation.Site/Assets/main.ts index f14b3f989..4a7241992 100644 --- a/src/Elastic.Documentation.Site/Assets/main.ts +++ b/src/Elastic.Documentation.Site/Assets/main.ts @@ -87,3 +87,15 @@ document.body.addEventListener('htmx:responseError', function (event) { window.location.assign(event.detail.pathInfo.requestPath) } }) + +// The body now has a data-docs-builder-version attribute, which is the version of the docs-builder +// used to generate this page. +// If there is a new version, we want to refresh the page to prevent broken layouts. +const currentDocsBuilderVersion = $('body').dataset.docsBuilderVersion +document.body.addEventListener('htmx:afterRequest', function (event) { + const targetDocsBuilderVersion = + event.detail.target.dataset.docsBuilderVersion + if (currentDocsBuilderVersion !== targetDocsBuilderVersion) { + window.location = event.detail.pathInfo.finalRequestPath + } +}) diff --git a/src/Elastic.Documentation.Site/_GlobalLayout.cshtml b/src/Elastic.Documentation.Site/_GlobalLayout.cshtml index a396783cf..d8e0ac9ed 100644 --- a/src/Elastic.Documentation.Site/_GlobalLayout.cshtml +++ b/src/Elastic.Documentation.Site/_GlobalLayout.cshtml @@ -9,6 +9,7 @@ @if (Model.GoogleTagManager.Enabled) { diff --git a/src/Elastic.Documentation.Site/_ViewModels.cs b/src/Elastic.Documentation.Site/_ViewModels.cs index c45d1c54e..53bd41652 100644 --- a/src/Elastic.Documentation.Site/_ViewModels.cs +++ b/src/Elastic.Documentation.Site/_ViewModels.cs @@ -17,6 +17,7 @@ public static class GlobalSections public record GlobalLayoutViewModel { + public required string DocsBuilderVersion { get; init; } public required string DocSetName { get; init; } public string Title { get; set; } = "Elastic Documentation"; public required string Description { get; init; } diff --git a/src/Elastic.Markdown/HtmlWriter.cs b/src/Elastic.Markdown/HtmlWriter.cs index 43eff502f..6d7f7c5e0 100644 --- a/src/Elastic.Markdown/HtmlWriter.cs +++ b/src/Elastic.Markdown/HtmlWriter.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information using System.IO.Abstractions; +using System.Reflection; using Elastic.Documentation; using Elastic.Documentation.Configuration.Builder; using Elastic.Documentation.Legacy; @@ -129,7 +130,9 @@ private async Task RenderLayout(MarkdownFile markdown, MarkdownDocument AllVersionsUrl = allVersionsUrl, LegacyPages = legacyPages?.Skip(1).ToArray(), VersionDropdownItems = VersionDrownDownItemViewModel.FromLegacyPageMappings(legacyPages?.Skip(1).ToArray()), - Products = allProducts + Products = allProducts, + DocsBuilderVersion = Assembly.GetExecutingAssembly().GetCustomAttributes() + .FirstOrDefault()?.InformationalVersion ?? "0.0.0" }); return await slice.RenderAsync(cancellationToken: ctx); } diff --git a/src/Elastic.Markdown/Page/Index.cshtml b/src/Elastic.Markdown/Page/Index.cshtml index d834c08af..45cd9c703 100644 --- a/src/Elastic.Markdown/Page/Index.cshtml +++ b/src/Elastic.Markdown/Page/Index.cshtml @@ -8,6 +8,7 @@ @functions { public MarkdownLayoutViewModel LayoutModel => new() { + DocsBuilderVersion = Model.DocsBuilderVersion, Layout = Model.CurrentDocument.YamlFrontMatter?.Layout, RenderHamburgerIcon = Model.CurrentDocument.YamlFrontMatter?.Layout != MarkdownPageLayout.LandingPage, DocSetName = Model.DocSetName, diff --git a/src/Elastic.Markdown/Page/IndexViewModel.cs b/src/Elastic.Markdown/Page/IndexViewModel.cs index d92559614..cc5766687 100644 --- a/src/Elastic.Markdown/Page/IndexViewModel.cs +++ b/src/Elastic.Markdown/Page/IndexViewModel.cs @@ -25,15 +25,12 @@ public class IndexViewModel public required DocumentationGroup Tree { get; init; } public required IReadOnlyCollection PageTocItems { get; init; } public required MarkdownFile CurrentDocument { get; init; } - public required INavigationItem CurrentNavigationItem { get; init; } public required INavigationItem? PreviousDocument { get; init; } public required INavigationItem? NextDocument { get; init; } public required INavigationItem[] Parents { get; init; } - public required string NavigationHtml { get; init; } public required string CurrentVersion { get; init; } - public required string? AllVersionsUrl { get; init; } public required LegacyPageMapping[]? LegacyPages { get; init; } public required VersionDrownDownItemViewModel[]? VersionDropdownItems { get; init; } @@ -43,13 +40,11 @@ public class IndexViewModel public required ApplicableTo? AppliesTo { get; init; } public required bool AllowIndexing { get; init; } public required Uri? CanonicalBaseUrl { get; init; } - public required GoogleTagManagerConfiguration GoogleTagManager { get; init; } - public required FeatureFlags Features { get; init; } public required StaticFileContentHashProvider StaticFileContentHashProvider { get; init; } - public required HashSet Products { get; init; } + public required string DocsBuilderVersion { get; init; } } public class VersionDrownDownItemViewModel