Skip to content

Commit d2db9d7

Browse files
committed
More core theme tweaks
1 parent 86a25b5 commit d2db9d7

10 files changed

+151
-51
lines changed

ApiDocsHelper.cs

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using Statiq.CodeAnalysis;
2+
using System.Text;
3+
4+
namespace TurnerSoftware.Compendium;
5+
6+
public class ApiDocsHelper
7+
{
8+
public static bool HasNonNamespaceChildren(IDocument document)
9+
{
10+
if (document.GetString(CodeAnalysisKeys.SpecificKind) == "Namespace")
11+
{
12+
foreach (var child in document.GetChildren(CodeAnalysisKeys.MemberTypes))
13+
{
14+
if (child.GetString(CodeAnalysisKeys.SpecificKind) != "Namespace")
15+
{
16+
return true;
17+
}
18+
}
19+
return false;
20+
}
21+
return true;
22+
}
23+
24+
public static string GetDisplayName(IDocument document)
25+
{
26+
var apiKind = document.GetString(CodeAnalysisKeys.SpecificKind);
27+
if (apiKind == "Namespace")
28+
{
29+
return $"{document.GetString(CodeAnalysisKeys.QualifiedName)} Namespace";
30+
}
31+
return $"{document.GetString(CodeAnalysisKeys.FullName)} {apiKind}";
32+
}
33+
34+
public static string GetPageTitle(IDocument document)
35+
{
36+
var displayName = GetDisplayName(document);
37+
var specificKind = document.GetString(CodeAnalysisKeys.SpecificKind);
38+
if (specificKind != "Namespace")
39+
{
40+
var containingNamespace = document.GetDocument(CodeAnalysisKeys.ContainingNamespace);
41+
if (containingNamespace is not null)
42+
{
43+
return $"{displayName} ({containingNamespace.GetString(Keys.Title)})";
44+
}
45+
}
46+
return displayName;
47+
}
48+
49+
public static string? GetPackageName(IDocument document)
50+
{
51+
var containingAssembly = document.GetDocument(CodeAnalysisKeys.ContainingAssembly);
52+
if (containingAssembly is not null)
53+
{
54+
return containingAssembly.GetString(CodeAnalysisKeys.DisplayName).RemoveEnd(".dll");
55+
}
56+
return null;
57+
}
58+
}

ApiExtensions.cs

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Statiq.CodeAnalysis;
22
using Statiq.Docs.Pipelines;
3+
using Statiq.Web.Modules;
34
using System.Text;
45

56
namespace TurnerSoftware.Compendium;
@@ -16,19 +17,11 @@ public ApiExtensions()
1617
new ConcatDocuments(nameof(Api)),
1718
new ExecuteConfig(Config.FromDocument((doc, ctx) =>
1819
{
19-
var coreName = $"{doc.GetString(CodeAnalysisKeys.FullName)} {doc.GetString(CodeAnalysisKeys.SpecificKind)}";
20-
var title = coreName;
21-
22-
var containingNamespace = doc.GetDocument(CodeAnalysisKeys.ContainingNamespace);
23-
if (containingNamespace is not null)
20+
return doc.Clone(new MetadataItems
2421
{
25-
title = $"{coreName} ({containingNamespace.GetString(Keys.Title)})";
26-
}
27-
28-
return doc.Clone(new Dictionary<string, object>()
29-
{
30-
[Keys.Title] = title
31-
});
22+
{ Keys.Title, ApiDocsHelper.GetPageTitle(doc) },
23+
//{ WebKeys.ContentType, ContentType.Content }
24+
});//, doc.ContentProvider.CloneWithMediaType(MediaTypes.Html));
3225
}))
3326
);
3427
}

BootstrapperExtensions.cs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace TurnerSoftware.Compendium;
2+
3+
public static class BootstrapperExtensions
4+
{
5+
public static TBootstrapper UseCompendiumTheme<TBootstrapper>(this TBootstrapper bootstrapper)
6+
where TBootstrapper : IBootstrapper => bootstrapper
7+
.ConfigureSettings()
8+
.AddPipelines();
9+
private static TBootstrapper AddPipelines<TBootstrapper>(this TBootstrapper bootstrapper)
10+
where TBootstrapper : IBootstrapper => bootstrapper
11+
.AddPipeline(typeof(Tailwind))
12+
.AddPipeline(typeof(ApiExtensions));
13+
14+
private static TBootstrapper ConfigureSettings<TBootstrapper>(this TBootstrapper bootstrapper)
15+
where TBootstrapper : IBootstrapper => bootstrapper.AddSettings(new Dictionary<string, object>
16+
{
17+
{ DocsKeys.ApiLayout, "Api/_ApiLayout" },
18+
//{ DocsKeys.OutputApiDocuments, false }
19+
});
20+
}

input/Shared/Api/Section/_Definition.cshtml

+4-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@{
2-
var containingNamespace = Document.GetDocument(CodeAnalysisKeys.ContainingNamespace);
32
var containingAssembly = Document.GetDocument(CodeAnalysisKeys.ContainingAssembly);
43

54
var summary = Document.GetString(CodeAnalysisKeys.Summary);
@@ -9,30 +8,17 @@
98
var derivedTypes = Document.GetDocumentList(CodeAnalysisKeys.DerivedTypes);
109
var implements = Document.GetDocumentList(CodeAnalysisKeys.Implements);
1110

12-
((List<(string, string)>)ViewData[Keys.Headings]).Add(("Definition", "Definition"));
1311
<section>
14-
<h2 id="Definition">Definition</h2>
15-
<div class="text-sm opacity-80 mb-3">
16-
<dl>
17-
<dt class="inline-block">Namespace:</dt>
18-
<dd class="inline-block ml-2">@Context.GetTypeLink(containingNamespace)</dd>
19-
</dl>
20-
<dl>
21-
<dt class="inline-block">Assembly:</dt>
22-
<dd class="inline-block ml-2">@Context.GetTypeLink(containingAssembly)</dd>
23-
</dl>
24-
</div>
25-
2612
@if (!summary.IsNullOrWhiteSpace())
2713
{
28-
<div class="mb-3">@Html.Raw(summary)</div>
14+
<div class="my-3">@Html.Raw(summary)</div>
2915
}
3016

3117
@if (!syntax.IsNullOrWhiteSpace())
3218
{
3319
<pre><code class="language-csharp">@syntax</code></pre>
3420
}
35-
21+
3622
@if (baseTypes?.Count > 0)
3723
{
3824
<dl>
@@ -54,7 +40,7 @@
5440
<dt class="inline-block">Derived</dt>
5541
<dd class="inline-block ml-2">
5642
<ul class="list-unstyled">
57-
@foreach (IDocument derivedType in derivedTypes)
43+
@foreach (var derivedType in derivedTypes)
5844
{
5945
<li>@Context.GetTypeLink(derivedType)</li>
6046
}
@@ -69,7 +55,7 @@
6955
<dt class="inline-block">Implements</dt>
7056
<dd class="inline-block ml-2">
7157
<ul class="list-unstyled">
72-
@foreach (IDocument implementsDocument in implements)
58+
@foreach (var implementsDocument in implements)
7359
{
7460
var implementsContainingTypeDocument = implementsDocument.GetDocument(CodeAnalysisKeys.ContainingType);
7561
<li>@Context.GetTypeLink(implementsContainingTypeDocument)[email protected](implementsDocument)</li>

input/Shared/Api/_ApiLayout.cshtml

+38-14
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,50 @@
2525
}
2626
}*@
2727

28-
@*@section Title {
29-
<div>@Html.Raw(Context.GetFormattedHtmlName(Document.GetTitle())) <small>@Document.GetString(CodeAnalysisKeys.SpecificKind)</small></div>
30-
}
31-
32-
@section ChildPages {
33-
}*@
34-
3528
@{
3629
// Use the ViewData to track headings since it's too late to figure them out from HTML by the time we're rendering
3730
// (anchor, title)
38-
ViewData[Keys.Headings] = new List<(string, string)>();
31+
var headings = new List<(string Id, string Name)>();
32+
ViewData[Keys.Headings] = headings;
3933
}
4034

4135
<section class="prose dark:prose-invert max-w-full">
42-
<h1>@Html.Raw(Context.GetFormattedHtmlName(Document.GetString(CodeAnalysisKeys.FullName))) @Document.GetString(CodeAnalysisKeys.SpecificKind)</h1>
43-
@await Html.PartialAsync("Api/Kind/_" + Document.GetString(CodeAnalysisKeys.Kind))
44-
</section>
36+
@{
37+
var parentDocument = Document.GetDocument(CodeAnalysisKeys.ContainingType) ?? Document.GetDocument(CodeAnalysisKeys.ContainingNamespace);
38+
if (parentDocument != null && parentDocument.GetString(Keys.Title) != "global")
39+
{
40+
@Context.GetTypeLink(parentDocument);
41+
}
42+
}
43+
<h1 class="mt-1 mb-2">@Html.Raw(Context.GetFormattedHtmlName(ApiDocsHelper.GetDisplayName(Document)))</h1>
44+
@{
45+
var apiKind = Document.GetString(CodeAnalysisKeys.Kind);
46+
if (apiKind != "Namespace")
47+
{
48+
var packageName = ApiDocsHelper.GetPackageName(Document);
49+
<span class="text-sm opacity-80">in <a rel="noopener" href="https://www.nuget.org/packages/@packageName">@packageName</a></span>
50+
}
51+
}
4552

46-
@*@section RightSidebar {
47-
@await Html.PartialAsync("Api/_RightSidebar")
48-
}*@
53+
<div class="grid grid-cols-aside">
54+
<div>
55+
@await Html.PartialAsync("Api/Kind/_" + Document.GetString(CodeAnalysisKeys.Kind))
56+
</div>
57+
@if (headings.Count > 0)
58+
{
59+
<aside>
60+
<div class="p-8">
61+
<span>On this page</span>
62+
<ul class="list-none p-0 m-0">
63+
@foreach (var heading in headings)
64+
{
65+
<li class="p-0"><a href="#@heading.Id">@heading.Name</a></li>
66+
}
67+
</ul>
68+
</div>
69+
</aside>
70+
}
71+
</div>
72+
</section>
4973

5074
@{ IgnoreBody(); }

input/Shared/_Layout.cshtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<link href="/assets/css/main.tailwind.min.css" rel="stylesheet" asp-append-version="true" />
4343
</head>
4444
<body class="font-copy">
45-
<div class="grid grid-cols-main max-w-7xl min-h-screen mx-auto">
45+
<div class="grid grid-cols-main max-w-[90rem] min-h-screen mx-auto">
4646
<aside class="bg-retro-brown text-white text-right p-4 md:p-8 border-r-4 border-primary-accent relative">
4747
<div class="absolute top-0 right-full w-screen h-full bg-retro-brown"></div>
4848
<header class="mb-8">

input/api/index.cshtml

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
ArchivePipelines: Api
22
ArchiveFilter: => GetString("Kind") == "Namespace"
33
ArchiveOrderKey: DisplayName
4-
DestinationPath: => GetPath("ApiPath").Combine("index.html")
5-
NoSidebar: true
64
Title: API Documentation
75
Xref: api
86
---
97
<section class="prose dark:prose-invert">
108
<h1>Namespaces</h1>
11-
@foreach (IDocument document in Model.GetChildren())
9+
@foreach (var namespaceDoc in Model.GetChildren())
1210
{
13-
<h3>@Context.GetTypeLink(document)</h3>
14-
string summary = document.GetString(CodeAnalysisKeys.Summary);
11+
var showNamespace = false;
12+
foreach (var memberTypeDoc in namespaceDoc.GetChildren(CodeAnalysisKeys.MemberTypes))
13+
{
14+
if (memberTypeDoc.GetString(CodeAnalysisKeys.SpecificKind) != "Namespace")
15+
{
16+
showNamespace = true;
17+
break;
18+
}
19+
}
20+
21+
if (!showNamespace)
22+
{
23+
continue;
24+
}
25+
26+
<h2>@Context.GetTypeLink(namespaceDoc)</h2>
27+
var summary = namespaceDoc.GetString(CodeAnalysisKeys.Summary);
1528
if (!summary.IsNullOrWhiteSpace())
1629
{
1730
<div>

tailwind.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ module.exports = {
8282
}),
8383
gridTemplateColumns: {
8484
'main': '360px minmax(0, 1fr)',
85+
'aside': 'minmax(0, 1fr) 200px'
8586
}
8687
}
8788
},

themesettings.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
//"ApiLayout": "Api/_ApiLayout",
3+
//"SourceFiles": "",
4+
//"ProjectFiles": "*.csproj",
5+
//"OutputApiDocuments": false //this doesn't work here
6+
}

themesettings.yml

-1
This file was deleted.

0 commit comments

Comments
 (0)