Skip to content

Commit 7d56a71

Browse files
authored
Revert "Refactor markdown and layout rendering by decoupling from `GlobalLayo…" (#1356)
This reverts commit 8df9149.
1 parent 8df9149 commit 7d56a71

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+314
-352
lines changed

src/Elastic.ApiExplorer/Endpoints/ApiEndpoint.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,10 @@ public EndpointNavigationItem(int depth, string url, ApiEndpoint apiEndpoint, La
5858
public ApiEndpoint Index { get; }
5959
public string Url { get; }
6060
public string NavigationTitle { get; }
61-
public bool Hidden => false;
6261

6362
public IReadOnlyCollection<OperationNavigationItem> NavigationItems { get; set; } = [];
6463

6564
public INodeNavigationItem<INavigationModel, INavigationItem> NavigationRoot { get; }
6665

6766
public INodeNavigationItem<INavigationModel, INavigationItem>? Parent { get; set; }
68-
69-
public int NavigationIndex { get; set; }
7067
}

src/Elastic.ApiExplorer/Endpoints/EndpointView.cshtml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@
77
{
88
DocSetName = "Api Explorer",
99
Description = "",
10+
Layout = null,
11+
PageTocItems = [],
1012
CurrentNavigationItem = Model.CurrentNavigationItem,
1113
Previous = null,
1214
Next = null,
1315
NavigationHtml = Model.NavigationHtml,
16+
LegacyPage = null,
1417
UrlPathPrefix = null,
18+
GithubEditUrl = null,
19+
ReportIssueUrl = null,
1520
AllowIndexing = false,
1621
CanonicalBaseUrl = null,
1722
GoogleTagManager = new GoogleTagManagerConfiguration(),
1823
Features = new FeatureFlags([]),
24+
Parents =
25+
[
26+
],
27+
Products = null,
1928
StaticFileContentHashProvider = Model.StaticFileContentHashProvider
2029
};
2130
}

src/Elastic.ApiExplorer/Landing/LandingNavigationItem.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ public class LandingNavigationItem : INodeNavigationItem<ApiLanding, EndpointNav
3434
public int Depth { get; }
3535
public ApiLanding Index { get; }
3636
public INodeNavigationItem<INavigationModel, INavigationItem>? Parent { get; set; }
37-
public int NavigationIndex { get; set; }
3837
public IReadOnlyCollection<EndpointNavigationItem> NavigationItems { get; set; } = [];
3938
public string Url { get; }
40-
public bool Hidden => false;
4139

4240
//TODO
4341
public string NavigationTitle { get; } = "API Documentation";

src/Elastic.ApiExplorer/Landing/LandingView.cshtml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@
77
{
88
DocSetName = "Api Explorer",
99
Description = "",
10+
Layout = null,
11+
PageTocItems = [],
1012
CurrentNavigationItem = Model.CurrentNavigationItem,
1113
Previous = null,
1214
Next = null,
1315
NavigationHtml = Model.NavigationHtml,
16+
LegacyPage = null,
1417
UrlPathPrefix = null,
18+
GithubEditUrl = null,
19+
ReportIssueUrl = null,
1520
AllowIndexing = false,
1621
CanonicalBaseUrl = null,
1722
GoogleTagManager = new GoogleTagManagerConfiguration(),
1823
Features = new FeatureFlags([]),
24+
Parents =
25+
[
26+
],
27+
Products = null,
1928
StaticFileContentHashProvider = Model.StaticFileContentHashProvider
2029
};
2130
}

src/Elastic.ApiExplorer/Operations/OperationNavigationItem.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,8 @@ public OperationNavigationItem(int depth, string url, ApiOperation apiOperation,
4747
public int Depth { get; }
4848
public ApiOperation Model { get; }
4949
public string Url { get; }
50-
public bool Hidden => false;
5150

5251
public string NavigationTitle { get; }
5352

5453
public INodeNavigationItem<INavigationModel, INavigationItem>? Parent { get; set; }
55-
56-
public int NavigationIndex { get; set; }
57-
5854
}

src/Elastic.ApiExplorer/Operations/OperationView.cshtml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@
77
{
88
DocSetName = "Api Explorer",
99
Description = "",
10+
Layout = null,
11+
PageTocItems = [],
1012
CurrentNavigationItem = Model.CurrentNavigationItem,
1113
Previous = null,
1214
Next = null,
1315
NavigationHtml = Model.NavigationHtml,
16+
LegacyPage = null,
1417
UrlPathPrefix = null,
18+
GithubEditUrl = null,
19+
ReportIssueUrl = null,
1520
AllowIndexing = false,
1621
CanonicalBaseUrl = null,
1722
GoogleTagManager = new GoogleTagManagerConfiguration(),
1823
Features = new FeatureFlags([]),
24+
Parents =
25+
[
26+
],
27+
Products = null,
1928
StaticFileContentHashProvider = Model.StaticFileContentHashProvider
2029
};
2130
}

src/Elastic.Documentation.Configuration/TableOfContents/ITocItem.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,4 @@ public record TocReference(Uri Source, ITableOfContentsScope TableOfContentsScop
2222
{
2323
public IReadOnlyDictionary<Uri, TocReference> TocReferences { get; } =
2424
Children.OfType<TocReference>().ToDictionary(kv => kv.Source, kv => kv);
25-
26-
/// <summary>
27-
/// A phantom table of contents is a table of contents that is not rendered in the UI but is used to generate the TOC.
28-
/// This should be used sparingly and needs explicit configuration in navigation.yml.
29-
/// It's typically used for container TOC that holds various other TOC's where its children are rehomed throughout the navigation.
30-
/// <para>Examples of phantom toc's:</para>
31-
/// <list type="">
32-
/// <item> - toc: elasticsearch://reference</item>
33-
/// <item> - toc: docs-content://</item>
34-
/// </list>
35-
/// <para>Because navigation.yml does exhaustive checks to ensure all toc.yml files are referenced, marking these containers as phantoms
36-
/// ensures that these skip validation checks
37-
/// </para>
38-
/// </summary>
39-
public bool IsPhantom { get; init; }
4025
}
41-

src/Elastic.Markdown/Slices/Layout/_Archive.cshtml renamed to src/Elastic.Documentation.Site/Layout/_Archive.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@inherits RazorSlice<MarkdownLayoutViewModel>
1+
@inherits RazorSlice<Elastic.Documentation.Site.GlobalLayoutViewModel>
22
<div class="bg-[#F5F7FA] w-full px-8 py-16 text-center">
33
<div class="container mx-auto mt-20">
44
<h1 class="text-4xl md:text-6xl">Archive</h1>

src/Elastic.Documentation.Site/Layout/_Head.cshtml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@inherits RazorSlice<Elastic.Documentation.Site.GlobalLayoutViewModel>
22
@using FontPreloader = Elastic.Documentation.Site.FileProviders.FontPreloader
3+
<head hx-head="merge">
34
<meta charset="utf-8">
45
<title>@Model.Title</title>
56
<meta name="description" content="@Model.Description">
@@ -34,3 +35,9 @@
3435
{
3536
<meta property="og:url" content="@Model.CanonicalUrl" />
3637
}
38+
@if (!string.IsNullOrEmpty(Model.Products))
39+
{
40+
<meta class="elastic" name="product_name" content="@(Model.Products)"/>
41+
<meta name="DC.subject" content="@(Model.Products)"/>
42+
}
43+
</head>

src/Elastic.Markdown/Slices/Layout/_LandingPage.cshtml renamed to src/Elastic.Documentation.Site/Layout/_LandingPage.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@inherits RazorSlice<MarkdownLayoutViewModel>
1+
@inherits RazorSlice<Elastic.Documentation.Site.GlobalLayoutViewModel>
22
<div class="w-full text-ink relative text-pretty">
33
<div class="w-full absolute top-0 left-0 right-0 htmx-indicator" id="htmx-indicator" role="status">
44
<div class="h-[2px] w-full overflow-hidden">

src/Elastic.Markdown/Slices/Layout/_NotFound.cshtml renamed to src/Elastic.Documentation.Site/Layout/_NotFound.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@inherits RazorSlice<MarkdownLayoutViewModel>
1+
@inherits RazorSlice<Elastic.Documentation.Site.GlobalLayoutViewModel>
22
<div class="p-12 font-body text-center flex flex-col items-center justify-center">
33
<span class="text-4xl font-sans font-semibold">Page not found</span>
44
<p class="mt-2">The page you are looking for could not be found.</p>

src/Elastic.Documentation.Site/Layout/_SecondaryNav.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<nav id="secondary-nav" class="bg-grey-10 border-t-1 border-grey-20 font-sans font-semibold text-sm text-ink-light md:text-base">
33
<div class="max-w-(--max-layout-width) flex mx-auto justify-between items-center p-6">
44
<div class="flex gap-2 flex-nowrap items-center">
5-
@if (Model.RenderHamburgerIcon)
5+
@if (Model.Layout != LayoutName.LandingPage)
66
{
77
@* ReSharper disable once Html.IdNotResolved *@
88
<label role="button" class="md:hidden cursor-pointer" for="pages-nav-hamburger">

src/Elastic.Markdown/Slices/LayoutName.cs renamed to src/Elastic.Documentation.Site/LayoutName.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
using System.Runtime.Serialization;
66

7-
namespace Elastic.Markdown.Slices;
7+
namespace Elastic.Documentation.Site;
88

99
public enum LayoutName
1010
{

src/Elastic.Documentation.Site/Navigation/INavigationItem.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ public interface INavigationItem
3030
/// TODO: This should be read-only however currently needs the setter in assembler.
3131
/// </remarks>
3232
INodeNavigationItem<INavigationModel, INavigationItem>? Parent { get; set; }
33-
34-
bool Hidden { get; }
35-
36-
int NavigationIndex { get; set; }
3733
}
3834

3935
/// Represents a leaf node in the navigation tree with associated model data.

src/Elastic.Documentation.Site/Navigation/_TocTreeNav.cshtml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
}
66
@foreach (var item in Model.SubTree.NavigationItems)
77
{
8-
if (item.Hidden)
9-
{
10-
continue;
11-
}
128
if (item is INodeNavigationItem<INavigationModel, INavigationItem> { NavigationItems.Count: 0, Index: not null } group)
139
{
1410
<li class="flex group/li pr-8 @(isTopLevel ? "font-semibold mt-6" : "mt-4")">
Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
@inherits RazorLayoutSlice<GlobalLayoutViewModel>
22
<!DOCTYPE html>
33
<html lang="en" class="h-screen" xmlns="http://www.w3.org/1999/html">
4-
<head hx-head="merge">
5-
@await RenderPartialAsync(_Head.Create(Model))
6-
@await RenderSectionAsync(GlobalSections.Head)
7-
</head>
4+
@await RenderPartialAsync(_Head.Create(Model))
5+
6+
@{
7+
var layout = Model.Layout;
8+
}
89

910
<body
1011
class="group/body text-ink has-[#primary-nav-hamburger:checked]:overflow-hidden"
@@ -17,9 +18,38 @@
1718
}
1819
@(await RenderPartialAsync(_Header.Create(Model)))
1920
<div id="main-container" class="flex flex-col items-center border-t-1 border-grey-20">
20-
@(await RenderBodyAsync())
21+
@switch (layout)
22+
{
23+
case LayoutName.NotFound:
24+
await RenderPartialAsync(_NotFound.Create(Model));
25+
break;
26+
case LayoutName.LandingPage:
27+
await RenderPartialAsync(_LandingPage.Create(Model));
28+
break;
29+
case LayoutName.Archive:
30+
await RenderPartialAsync(_Archive.Create(Model));
31+
break;
32+
default:
33+
await RenderBodyAsync();
34+
break;
35+
}
2136
</div>
2237
@await RenderPartialAsync(_Footer.Create(Model))
23-
@await RenderSectionAsync(GlobalSections.Footer)
38+
@if (layout is not LayoutName.Archive)
39+
{
40+
<aside id="dismissible-banner" class="admonition tip">
41+
<div class="container flex justify-between items-center mx-auto">
42+
<p>
43+
Welcome to the docs for the <a class="link text-base" href="/docs/get-started/versioning-availability#find-docs-for-your-product-version">latest Elastic product versions</a>, including Elastic Stack 9.0 and Elastic Cloud Serverless.
44+
To view previous versions, go to <a class="link text-base" target="_blank" href="https://elastic.co/guide">elastic.co/guide</a>.
45+
</p>
46+
<button id="dismissible-button">
47+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
48+
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12"/>
49+
</svg>
50+
</button>
51+
</div>
52+
</aside>
53+
}
2454
</body>
2555
</html>

src/Elastic.Documentation.Site/_ViewModels.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,38 @@
44

55
using Elastic.Documentation.Configuration.Assembler;
66
using Elastic.Documentation.Configuration.Builder;
7+
using Elastic.Documentation.Legacy;
78
using Elastic.Documentation.Site.FileProviders;
89
using Elastic.Documentation.Site.Navigation;
910

1011
namespace Elastic.Documentation.Site;
1112

12-
public static class GlobalSections
13-
{
14-
public const string Head = "head";
15-
public const string Footer = "footer";
16-
}
17-
1813
public class GlobalLayoutViewModel
1914
{
2015
public required string DocSetName { get; init; }
2116
public string Title { get; set; } = "Elastic Documentation";
2217
public required string Description { get; init; }
18+
public required LayoutName? Layout { get; init; }
2319

24-
public required INavigationItem CurrentNavigationItem { get; init; }
20+
public required IReadOnlyCollection<PageTocItem> PageTocItems { get; init; }
21+
public required INavigationItem? CurrentNavigationItem { get; init; }
2522
public required INavigationItem? Previous { get; init; }
2623
public required INavigationItem? Next { get; init; }
27-
2824
public required string NavigationHtml { get; init; }
25+
public required LegacyPageMapping? LegacyPage { get; init; }
2926
public required string? UrlPathPrefix { get; init; }
27+
public required string? GithubEditUrl { get; init; }
28+
public required string? ReportIssueUrl { get; init; }
29+
public required bool AllowIndexing { get; init; }
3030
public required Uri? CanonicalBaseUrl { get; init; }
31+
public required GoogleTagManagerConfiguration GoogleTagManager { get; init; }
3132
public string? CanonicalUrl => CanonicalBaseUrl is not null ?
3233
new Uri(CanonicalBaseUrl, CurrentNavigationItem?.Url).ToString().TrimEnd('/') : null;
33-
3434
public required FeatureFlags Features { get; init; }
3535

36-
// TODO move to @inject
37-
public required GoogleTagManagerConfiguration GoogleTagManager { get; init; }
38-
public required bool AllowIndexing { get; init; }
39-
public required StaticFileContentHashProvider StaticFileContentHashProvider { get; init; }
36+
public required INavigationItem[] Parents { get; init; }
4037

41-
public bool RenderHamburgerIcon { get; init; } = true;
38+
public required string? Products { get; init; }
4239

4340
public string Static(string path)
4441
{
@@ -49,10 +46,19 @@ public string Static(string path)
4946
: $"{UrlPathPrefix}/{staticPath}?v={contentHash}";
5047
}
5148

49+
// TODO move to @inject
50+
public required StaticFileContentHashProvider StaticFileContentHashProvider { get; init; }
51+
5252
public string Link(string path)
5353
{
5454
path = path.AsSpan().TrimStart('/').ToString();
5555
return $"{UrlPathPrefix}/{path}";
5656
}
5757
}
5858

59+
public record PageTocItem
60+
{
61+
public required string Heading { get; init; }
62+
public required string Slug { get; init; }
63+
public required int Level { get; init; }
64+
}

src/Elastic.Markdown/IO/DocumentationFile.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Elastic.Documentation.Site;
66
using Elastic.Markdown.Myst;
77
using Elastic.Markdown.Myst.FrontMatter;
8-
using Elastic.Markdown.Slices;
98

109
namespace Elastic.Markdown.IO;
1110

0 commit comments

Comments
 (0)