-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy path_Layout.cshtml
More file actions
117 lines (112 loc) · 3.84 KB
/
_Layout.cshtml
File metadata and controls
117 lines (112 loc) · 3.84 KB
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
@inherits RazorLayoutSlice<MarkdownLayoutViewModel>
@using Elastic.Markdown
@implements IUsesLayout<Elastic.Documentation.Site._GlobalLayout, GlobalLayoutViewModel>
@functions {
public GlobalLayoutViewModel LayoutModel => Model;
protected override async Task ExecuteSectionAsync(string name)
{
if (name == GlobalSections.Footer && Model.Layout is not MarkdownPageLayout.Archive)
{
//this ensures we forward footer sections declared in this project into to GlobalLayout view's section
await RenderSectionAsync(GlobalSections.Footer);
}
if (name == GlobalSections.Head)
{
if (Model.RedirectUrl is { } redirectUrl && Model.Layout is not MarkdownPageLayout.Archive)
{
var encodedUrl = System.Text.Encodings.Web.JavaScriptEncoder.Default.Encode(redirectUrl);
<script>window.location.replace('@(new HtmlString(encodedUrl))');</script>
}
//this ensures we forward head sections declared in this project into to GlobalLayout view's section
await RenderSectionAsync(GlobalSections.Head);
}
}
private bool RenderHeaderAndFooter => Model.Layout is not MarkdownPageLayout.FullSearch;
private async Task RenderDefault()
{
<div class="relative">
<div class="min-h-screen
w-full
max-w-(--max-layout-width)
mx-auto
md:px-4
">
<div class="min-h-screen grid grid-cols-1 md:grid-cols-[var(--max-sidebar-width)_1fr] gap-4">
<main id="content-container" class="min-w-0 flex flex-col lg:grid lg:grid-cols-[minmax(0,var(--max-text-width))_minmax(0,var(--max-sidebar-width))] justify-end mx-4 gap-4 md:order-2">
@{
var breadcrumbs = Model.Breadcrumbs.ToList();
var breadcrumbVisible = breadcrumbs.Count > 0 && (breadcrumbs.Count > 1 || Model.BuildType != BuildType.Isolated);
}
<div class="mb-9 mt-0 min-w-0 order-2 lg:order-1 @(breadcrumbVisible ? "" : "pt-6")">
@await RenderPartialAsync(_Breadcrumbs.Create(Model))
<article id="markdown-content" class="markdown-content min-w-0">
<input type="checkbox" class="hidden" id="pages-nav-hamburger">
@await RenderBodyAsync()
</article>
@await RenderPartialAsync(_PrevNextNav.Create(Model))
@if (Model.Features.WebsiteSearchEnabled && Model.Features.WebsiteSearchScriptUrl is not null)
{
<div id="elastic-website-search-input-container"
class="sticky bottom-8 mt-8 z-40">
</div>
}
</div>
@await RenderPartialAsync(_TableOfContents.Create(Model))
</main>
@await RenderPartialAsync(_PagesNav.Create<GlobalLayoutViewModel>(Model))
</div>
</div>
</div>
}
}
@if (RenderHeaderAndFooter)
{
if (Model.BuildType == BuildType.Assembler)
{
@(await RenderPartialAsync(_AssemblerHeader.Create<GlobalLayoutViewModel>(Model)))
}
else
{
@(await RenderPartialAsync(_IsolatedHeader.Create<GlobalLayoutViewModel>(Model)))
}
}
<div id="main-container">
@switch (Model.Layout)
{
case MarkdownPageLayout.NotFound:
await RenderPartialAsync(_NotFound.Create(Model));
break;
case MarkdownPageLayout.LandingPage:
await RenderPartialAsync(_LandingPage.Create(Model));
break;
case MarkdownPageLayout.Archive:
await RenderPartialAsync(_Archive.Create(Model));
break;
case MarkdownPageLayout.FullSearch:
await RenderPartialAsync(_FullSearch.Create(Model));
break;
default:
await RenderDefault();
break;
}
</div>
@if (Model.Features.WebsiteSearchEnabled && Model.Features.WebsiteSearchScriptUrl is not null)
{
<elastic-website-search
nav-mode="off"
chat-enabled="true"
chat-mode="input"
chat-input-container="#elastic-website-search-input-container">
</elastic-website-search>
}
@if (RenderHeaderAndFooter)
{
if (Model.BuildType == BuildType.Assembler)
{
@(await RenderPartialAsync(_AssemblerFooter.Create<GlobalLayoutViewModel>(Model)))
}
else
{
@(await RenderPartialAsync(_IsolatedFooter.Create<GlobalLayoutViewModel>(Model)))
}
}