File tree Expand file tree Collapse file tree 5 files changed +18
-11
lines changed Expand file tree Collapse file tree 5 files changed +18
-11
lines changed Original file line number Diff line number Diff line change 44
55using System . IO . Abstractions ;
66using System . Runtime . InteropServices ;
7+ using System . Security . Cryptography ;
8+ using System . Text ;
79using Elastic . Documentation . Diagnostics ;
810using Elastic . Documentation . Navigation ;
911using Elastic . Markdown . Diagnostics ;
@@ -51,6 +53,7 @@ DocumentationSet set
5153 _configurationFile = build . Configuration . SourceFile ;
5254 _globalSubstitutions = build . Configuration . Substitutions ;
5355 _set = set ;
56+ Id = Convert . ToHexString ( SHA256 . HashData ( Encoding . UTF8 . GetBytes ( FilePath ) ) ) [ ..8 ] ;
5457 //may be updated by DocumentationGroup.ProcessTocItems
5558 //todo refactor mutability of MarkdownFile as a whole
5659 ScopeDirectory = build . Configuration . ScopeDirectory ;
@@ -65,7 +68,7 @@ DocumentationSet set
6568
6669 public Uri NavigationSource { get ; set ; }
6770
68- public string Id { get ; } = Guid . NewGuid ( ) . ToString ( "N" ) [ .. 8 ] ;
71+ public string Id { get ; }
6972
7073 private IDiagnosticsCollector Collector { get ; }
7174
Original file line number Diff line number Diff line change 44
55using System . Diagnostics ;
66using System . Diagnostics . CodeAnalysis ;
7+ using System . Security . Cryptography ;
8+ using System . Text ;
79using Elastic . Documentation ;
810using Elastic . Documentation . Configuration . TableOfContents ;
911
@@ -125,7 +127,7 @@ public class DocumentationGroup : INavigationGroup
125127{
126128 private readonly TableOfContentsTreeCollector _treeCollector ;
127129
128- public string Id { get ; } = Guid . NewGuid ( ) . ToString ( "N" ) [ .. 8 ] ;
130+ public string Id { get ; }
129131
130132 public string NavigationRootId => NavigationRoot . Id ;
131133
@@ -196,6 +198,7 @@ protected DocumentationGroup(
196198 GroupsInOrder = groups ;
197199 FilesInOrder = files ;
198200 NavigationItems = navigationItems ;
201+ Id = Convert . ToHexString ( SHA256 . HashData ( Encoding . UTF8 . GetBytes ( FolderName + depth ) ) ) [ ..8 ] ;
199202
200203 if ( Index is not null )
201204 FilesInOrder = [ .. FilesInOrder . Except ( [ Index ] ) ] ;
Original file line number Diff line number Diff line change 11// Licensed to Elasticsearch B.V under one or more agreements.
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
4+
5+ using System . Security . Cryptography ;
46using System . Text ;
57using Elastic . Markdown . Myst . Settings ;
68
@@ -56,7 +58,13 @@ public class ImageViewModel
5658 public required string ? Target { get ; init ; }
5759 public required string ? Width { get ; init ; }
5860 public required string ? ImageUrl { get ; init ; }
59- public string UniqueImageId { get ; } = Guid . NewGuid ( ) . ToString ( "N" ) [ ..8 ] ;
61+
62+ private string ? _uniqueImageId ;
63+
64+ public string UniqueImageId =>
65+ _uniqueImageId ??= string . IsNullOrEmpty ( ImageUrl )
66+ ? Guid . NewGuid ( ) . ToString ( "N" ) [ ..8 ] // fallback to a random ID if ImageUrl is null or empty
67+ : Convert . ToHexString ( SHA256 . HashData ( Encoding . UTF8 . GetBytes ( ImageUrl ) ) ) [ ..8 ] ;
6068 public required string ? Screenshot { get ; init ; }
6169
6270 public string Style
Original file line number Diff line number Diff line change 22<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" >
33 <nav
44 id =" pages-nav"
5- class =" sidebar-nav h-full"
6- @* used to invalidate session storage *@
7- data-current-navigation =" @LayoutViewModel.CurrentNavigationId" >
5+ class =" sidebar-nav h-full" >
86 @( new HtmlString (Model .NavigationHtml ))
97 </nav >
108 @* ReSharper disable once Html.IdNotResolved *@
Original file line number Diff line number Diff line change @@ -46,11 +46,6 @@ public class IndexViewModel
4646public class LayoutViewModel
4747{
4848 public required string DocSetName { get ; init ; }
49-
50- /// Used to identify the navigation for the current compilation
51- /// We want to reset users sessionStorage every time this changes to invalidate
52- /// the guids that no longer exist
53- public static string CurrentNavigationId { get ; } = Guid . NewGuid ( ) . ToString ( "N" ) [ ..8 ] ;
5449 public string Title { get ; set ; } = "Elastic Documentation" ;
5550 public required string Description { get ; init ; }
5651 public required IReadOnlyCollection < PageTocItem > PageTocItems { get ; init ; }
You can’t perform that action at this time.
0 commit comments