File tree Expand file tree Collapse file tree 6 files changed +33
-12
lines changed Expand file tree Collapse file tree 6 files changed +33
-12
lines changed Original file line number Diff line number Diff line change
1
+ // Licensed to Elasticsearch B.V under one or more agreements.
2
+ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3
+ // See the LICENSE file in the project root for more information
4
+
5
+ using System . Security . Cryptography ;
6
+ using System . Text ;
7
+
8
+ namespace Elastic . Markdown . Helpers ;
9
+
10
+ public static class ShortId
11
+ {
12
+ public static string Create ( params string [ ] components ) => Convert . ToHexString ( SHA256 . HashData ( Encoding . UTF8 . GetBytes ( string . Join ( "" , components ) ) ) ) [ ..8 ] ;
13
+ }
Original file line number Diff line number Diff line change 4
4
5
5
using System . IO . Abstractions ;
6
6
using System . Runtime . InteropServices ;
7
+ using System . Security . Cryptography ;
8
+ using System . Text ;
7
9
using Elastic . Documentation . Diagnostics ;
8
10
using Elastic . Documentation . Navigation ;
9
11
using Elastic . Markdown . Diagnostics ;
@@ -51,6 +53,7 @@ DocumentationSet set
51
53
_configurationFile = build . Configuration . SourceFile ;
52
54
_globalSubstitutions = build . Configuration . Substitutions ;
53
55
_set = set ;
56
+ Id = ShortId . Create ( FilePath ) ;
54
57
//may be updated by DocumentationGroup.ProcessTocItems
55
58
//todo refactor mutability of MarkdownFile as a whole
56
59
ScopeDirectory = build . Configuration . ScopeDirectory ;
@@ -65,7 +68,7 @@ DocumentationSet set
65
68
66
69
public Uri NavigationSource { get ; set ; }
67
70
68
- public string Id { get ; } = Guid . NewGuid ( ) . ToString ( "N" ) [ .. 8 ] ;
71
+ public string Id { get ; }
69
72
70
73
private IDiagnosticsCollector Collector { get ; }
71
74
Original file line number Diff line number Diff line change 4
4
5
5
using System . Diagnostics ;
6
6
using System . Diagnostics . CodeAnalysis ;
7
+ using System . Security . Cryptography ;
8
+ using System . Text ;
7
9
using Elastic . Documentation ;
8
10
using Elastic . Documentation . Configuration . TableOfContents ;
11
+ using Elastic . Markdown . Helpers ;
9
12
10
13
namespace Elastic . Markdown . IO . Navigation ;
11
14
@@ -125,7 +128,7 @@ public class DocumentationGroup : INavigationGroup
125
128
{
126
129
private readonly TableOfContentsTreeCollector _treeCollector ;
127
130
128
- public string Id { get ; } = Guid . NewGuid ( ) . ToString ( "N" ) [ .. 8 ] ;
131
+ public string Id { get ; }
129
132
130
133
public string NavigationRootId => NavigationRoot . Id ;
131
134
@@ -196,7 +199,7 @@ protected DocumentationGroup(
196
199
GroupsInOrder = groups ;
197
200
FilesInOrder = files ;
198
201
NavigationItems = navigationItems ;
199
-
202
+ Id = ShortId . Create ( NavigationSource . ToString ( ) , FolderName ) ;
200
203
if ( Index is not null )
201
204
FilesInOrder = [ .. FilesInOrder . Except ( [ Index ] ) ] ;
202
205
}
Original file line number Diff line number Diff line change 1
1
// Licensed to Elasticsearch B.V under one or more agreements.
2
2
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3
3
// See the LICENSE file in the project root for more information
4
+
5
+ using System . Security . Cryptography ;
4
6
using System . Text ;
7
+ using Elastic . Markdown . Helpers ;
5
8
using Elastic . Markdown . Myst . Settings ;
6
9
7
10
namespace Elastic . Markdown . Slices . Directives ;
@@ -56,7 +59,13 @@ public class ImageViewModel
56
59
public required string ? Target { get ; init ; }
57
60
public required string ? Width { get ; init ; }
58
61
public required string ? ImageUrl { get ; init ; }
59
- public string UniqueImageId { get ; } = Guid . NewGuid ( ) . ToString ( "N" ) [ ..8 ] ;
62
+
63
+ private string ? _uniqueImageId ;
64
+
65
+ public string UniqueImageId =>
66
+ _uniqueImageId ??= string . IsNullOrEmpty ( ImageUrl )
67
+ ? Guid . NewGuid ( ) . ToString ( "N" ) [ ..8 ] // fallback to a random ID if ImageUrl is null or empty
68
+ : ShortId . Create ( ImageUrl ) ;
60
69
public required string ? Screenshot { get ; init ; }
61
70
62
71
public string Style
Original file line number Diff line number Diff line change 2
2
<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" >
3
3
<nav
4
4
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" >
8
6
@( new HtmlString (Model .NavigationHtml ))
9
7
</nav >
10
8
@* ReSharper disable once Html.IdNotResolved *@
Original file line number Diff line number Diff line change @@ -46,11 +46,6 @@ public class IndexViewModel
46
46
public class LayoutViewModel
47
47
{
48
48
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 ] ;
54
49
public string Title { get ; set ; } = "Elastic Documentation" ;
55
50
public required string Description { get ; init ; }
56
51
public required IReadOnlyCollection < PageTocItem > PageTocItems { get ; init ; }
You can’t perform that action at this time.
0 commit comments