Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Elastic.Markdown/IO/MarkdownFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

using System.IO.Abstractions;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using Elastic.Documentation.Diagnostics;
using Elastic.Documentation.Navigation;
using Elastic.Markdown.Diagnostics;
Expand Down Expand Up @@ -51,6 +53,7 @@ DocumentationSet set
_configurationFile = build.Configuration.SourceFile;
_globalSubstitutions = build.Configuration.Substitutions;
_set = set;
Id = Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(FilePath)))[..8];
//may be updated by DocumentationGroup.ProcessTocItems
//todo refactor mutability of MarkdownFile as a whole
ScopeDirectory = build.Configuration.ScopeDirectory;
Expand All @@ -65,7 +68,7 @@ DocumentationSet set

public Uri NavigationSource { get; set; }

public string Id { get; } = Guid.NewGuid().ToString("N")[..8];
public string Id { get; }

private IDiagnosticsCollector Collector { get; }

Expand Down
6 changes: 4 additions & 2 deletions src/Elastic.Markdown/IO/Navigation/DocumentationGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Security.Cryptography;
using System.Text;
using Elastic.Documentation;
using Elastic.Documentation.Configuration.TableOfContents;

Expand Down Expand Up @@ -125,7 +127,7 @@ public class DocumentationGroup : INavigationGroup
{
private readonly TableOfContentsTreeCollector _treeCollector;

public string Id { get; } = Guid.NewGuid().ToString("N")[..8];
public string Id { get; }

public string NavigationRootId => NavigationRoot.Id;

Expand Down Expand Up @@ -196,7 +198,7 @@ protected DocumentationGroup(
GroupsInOrder = groups;
FilesInOrder = files;
NavigationItems = navigationItems;

Id = Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(NavigationSource + FolderName + depth)))[..8];
if (Index is not null)
FilesInOrder = [.. FilesInOrder.Except([Index])];
}
Expand Down
10 changes: 9 additions & 1 deletion src/Elastic.Markdown/Slices/Directives/_ViewModels.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.Security.Cryptography;
using System.Text;
using Elastic.Markdown.Myst.Settings;

Expand Down Expand Up @@ -56,7 +58,13 @@ public class ImageViewModel
public required string? Target { get; init; }
public required string? Width { get; init; }
public required string? ImageUrl { get; init; }
public string UniqueImageId { get; } = Guid.NewGuid().ToString("N")[..8];

private string? _uniqueImageId;

public string UniqueImageId =>
_uniqueImageId ??= string.IsNullOrEmpty(ImageUrl)
? Guid.NewGuid().ToString("N")[..8] // fallback to a random ID if ImageUrl is null or empty
: Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(ImageUrl)))[..8];
public required string? Screenshot { get; init; }

public string Style
Expand Down
4 changes: 1 addition & 3 deletions src/Elastic.Markdown/Slices/Layout/_PagesNav.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
<aside class="sidebar bg-white fixed md:sticky shadow-2xl md:shadow-none left-[100%] group-has-[#pages-nav-hamburger:checked]/body:left-0 bottom-0 md:left-auto pl-6 md:pl-2 top-[calc(var(--offset-top)+1px)] w-[80%] md:w-auto shrink-0 border-r-1 border-r-grey-20 z-40 md:z-auto">
<nav
id="pages-nav"
class="sidebar-nav h-full"
@* used to invalidate session storage *@
data-current-navigation="@LayoutViewModel.CurrentNavigationId">
class="sidebar-nav h-full">
@(new HtmlString(Model.NavigationHtml))
</nav>
@* ReSharper disable once Html.IdNotResolved *@
Expand Down
5 changes: 0 additions & 5 deletions src/Elastic.Markdown/Slices/_ViewModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ public class IndexViewModel
public class LayoutViewModel
{
public required string DocSetName { get; init; }

/// Used to identify the navigation for the current compilation
/// We want to reset users sessionStorage every time this changes to invalidate
/// the guids that no longer exist
public static string CurrentNavigationId { get; } = Guid.NewGuid().ToString("N")[..8];
Comment on lines -49 to -53
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this entirely. Since it's original purpose doesn't exist anymore.

(persistent navigation state)

public string Title { get; set; } = "Elastic Documentation";
public required string Description { get; init; }
public required IReadOnlyCollection<PageTocItem> PageTocItems { get; init; }
Expand Down
Loading