-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path_ViewModels.cs
146 lines (127 loc) · 5.31 KB
/
_ViewModels.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// 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 Elastic.Markdown.IO;
using Elastic.Markdown.IO.Configuration;
using Elastic.Markdown.IO.Navigation;
using Elastic.Markdown.Myst.FrontMatter;
namespace Elastic.Markdown.Slices;
public class IndexViewModel
{
public required string SiteName { get; init; }
public required string DocSetName { get; init; }
public required string Title { get; init; }
public required string Description { get; init; }
public required string TitleRaw { get; init; }
public required string MarkdownHtml { get; init; }
public required DocumentationGroup Tree { get; init; }
public required IReadOnlyCollection<PageTocItem> PageTocItems { get; init; }
public required MarkdownFile CurrentDocument { get; init; }
public required MarkdownFile? PreviousDocument { get; init; }
public required MarkdownFile? NextDocument { get; init; }
public required string NavigationHtml { get; init; }
public required string? UrlPathPrefix { get; init; }
public required string? GithubEditUrl { get; init; }
public required string? ReportIssueUrl { get; init; }
public required ApplicableTo? Applies { get; init; }
public required bool AllowIndexing { get; init; }
public required Uri? CanonicalBaseUrl { get; init; }
public required bool EnableGoogleTagManager { get; init; }
public required FeatureFlags Features { get; init; }
public required StaticFileContentHashProvider StaticFileContentHashProvider { get; init; }
}
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];
public string Title { get; set; } = "Elastic Documentation";
public required string Description { get; init; }
public required IReadOnlyCollection<PageTocItem> PageTocItems { get; init; }
public required MarkdownFile CurrentDocument { get; init; }
public required MarkdownFile? Previous { get; init; }
public required MarkdownFile? Next { get; init; }
public required string NavigationHtml { get; init; }
public required string? UrlPathPrefix { get; init; }
public required string? GithubEditUrl { get; init; }
public required string? ReportIssueUrl { get; init; }
public required bool AllowIndexing { get; init; }
public required Uri? CanonicalBaseUrl { get; init; }
public required bool EnableGoogleTagManager { get; init; }
public string? CanonicalUrl => CanonicalBaseUrl is not null ? new Uri(CanonicalBaseUrl, CurrentDocument.Url).ToString() : null;
public required FeatureFlags Features { get; init; }
private MarkdownFile[]? _parents;
public MarkdownFile[] Parents
{
get
{
if (_parents is not null)
return _parents;
_parents = [.. CurrentDocument.YieldParents()];
return _parents;
}
}
public string Static(string path)
{
var staticPath = $"_static/{path.TrimStart('/')}";
var contentHash = StaticFileContentHashProvider.GetContentHash(path.TrimStart('/'));
return string.IsNullOrEmpty(contentHash)
? $"{UrlPathPrefix}/{staticPath}"
: $"{UrlPathPrefix}/{staticPath}?v={contentHash}";
}
public required StaticFileContentHashProvider StaticFileContentHashProvider { get; init; }
public string Link(string path)
{
path = path.AsSpan().TrimStart('/').ToString();
return $"{UrlPathPrefix}/{path}";
}
public bool IsLandingPage => Features.IsLandingPageEnabled && CurrentDocument.Url == Link("/");
}
public record PageTocItem
{
public required string Heading { get; init; }
public required string Slug { get; init; }
public required int Level { get; init; }
}
public class NavigationViewModel
{
public required string Title { get; init; }
public required string TitleUrl { get; init; }
public required INavigation Tree { get; init; }
//public required MarkdownFile CurrentDocument { get; init; }
/// controls whether to split tree automatically
public required bool IsPrimaryNavEnabled { get; init; }
public required bool IsGlobalAssemblyBuild { get; init; }
public required IEnumerable<GroupNavigationItem> TopLevelItems { get; init; }
}
public class NavigationTreeItem
{
public required int Level { get; init; }
//public required MarkdownFile CurrentDocument { get; init; }
public required INavigation SubTree { get; init; }
public required bool IsPrimaryNavEnabled { get; init; }
public required bool IsGlobalAssemblyBuild { get; init; }
public required string RootNavigationId { get; set; }
}
public class PrimaryNavViewModel
{
public required List<PrimaryNavItemViewModel> Items { get; init; } = [];
}
public class PrimaryNavItemViewModel
{
public required string Title { get; init; }
public string? Url { get; init; }
public string? HtmxAttributes { get; init; }
public List<PrimaryNavDropdownItemViewModel> DropdownItems { get; init; } = [];
}
public class PrimaryNavDropdownItemViewModel
{
public required string Title { get; init; }
public required string Description { get; init; }
public string? IconPath { get; init; }
public string? IconAlt { get; init; }
public required string Url { get; init; }
public required string HtmxAttributes { get; init; }
}