Skip to content

Commit c6c3327

Browse files
committed
Some initial docs.
1 parent d1daf4b commit c6c3327

File tree

215 files changed

+20972
-0
lines changed

Some content is hidden

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

215 files changed

+20972
-0
lines changed

docs/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
output/
2+
.vs/

docs/Program.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Threading.Tasks;
2+
using Statiq.App;
3+
using Statiq.Docs;
4+
5+
namespace docs
6+
{
7+
public class Program
8+
{
9+
public static async Task<int> Main(string[] args) =>
10+
await Bootstrapper
11+
.Factory
12+
.CreateDocs(args)
13+
.RunAsync();
14+
}
15+
}

docs/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Preview docs
2+
3+
```
4+
dotnet run -- preview
5+
```

docs/docs.csproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Compile Remove="output\**" />
10+
<EmbeddedResource Remove="output\**" />
11+
<None Remove="output\**" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Statiq.CodeAnalysis" Version="1.0.0-beta.41" />
16+
<!--<PackageReference Include="Statiq.Docs" Version="1.0.0-alpha.1" />-->
17+
<PackageReference Include="Statiq.Web" Version="1.0.0-beta.27" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<ProjectReference Include="../../Statiq.Docs\src\Statiq.Docs\Statiq.Docs.csproj" />
22+
</ItemGroup>
23+
24+
</Project>

docs/docs.sln

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.6.30114.105
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "docs", "docs.csproj", "{C7FC1074-EE53-4787-8E49-F3805698606D}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Debug|x64 = Debug|x64
12+
Debug|x86 = Debug|x86
13+
Release|Any CPU = Release|Any CPU
14+
Release|x64 = Release|x64
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{C7FC1074-EE53-4787-8E49-F3805698606D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{C7FC1074-EE53-4787-8E49-F3805698606D}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{C7FC1074-EE53-4787-8E49-F3805698606D}.Debug|x64.ActiveCfg = Debug|Any CPU
24+
{C7FC1074-EE53-4787-8E49-F3805698606D}.Debug|x64.Build.0 = Debug|Any CPU
25+
{C7FC1074-EE53-4787-8E49-F3805698606D}.Debug|x86.ActiveCfg = Debug|Any CPU
26+
{C7FC1074-EE53-4787-8E49-F3805698606D}.Debug|x86.Build.0 = Debug|Any CPU
27+
{C7FC1074-EE53-4787-8E49-F3805698606D}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{C7FC1074-EE53-4787-8E49-F3805698606D}.Release|Any CPU.Build.0 = Release|Any CPU
29+
{C7FC1074-EE53-4787-8E49-F3805698606D}.Release|x64.ActiveCfg = Release|Any CPU
30+
{C7FC1074-EE53-4787-8E49-F3805698606D}.Release|x64.Build.0 = Release|Any CPU
31+
{C7FC1074-EE53-4787-8E49-F3805698606D}.Release|x86.ActiveCfg = Release|Any CPU
32+
{C7FC1074-EE53-4787-8E49-F3805698606D}.Release|x86.Build.0 = Release|Any CPU
33+
EndGlobalSection
34+
EndGlobal

docs/input/dap.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Title: Debug Adapter Protocol
2+
ShowInSidebar: true
3+
---

docs/input/index.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Title: C# Language Server Protocol
2+
NoSidebar: false
3+
ShowInSidebar: false
4+
NoTitle: true
5+
ArchiveSources: '*.md'
6+
ArchiveOrderDescending: true
7+
---
8+
9+
# Welcome!
10+
11+
You can explore the documentation by selecting sections from the navigation bar above.

docs/jsonrpc.md renamed to docs/input/jsonrpc.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Title: JSON RPC
2+
ShowInSidebar: true
3+
---
4+
15
# Using Json Rpc Standalone
26
One of the benefits of the [JSON-RPC protocol](https://www.jsonrpc.org/specification) is that communication can be fully bi-directional. Through some sort of interface agreement, like LSP / DAP, both sides can act as both client (sender) and server (reciever).
37

docs/lsp.md renamed to docs/input/lsp.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Title: Language Server Protocol
2+
ShowInSidebar: true
3+
---
4+
15
# Implementing the Language Server Protocol
26

37
The goal of this library is to implement [Language Server Protocol](https://microsoft.github.io/language-server-protocol/) as closely as possible

docs/source-generation.md renamed to docs/input/source-generation.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Title: Source Generators
2+
ShowInSidebar: true
3+
---
4+
15
# Source Generators
26
We have built a few source generators to help with aid with implementing the plumbing of all the things. The goals of using source generation this way is to ensure that errors and mistakes are avoided and don't cause issues.
37

docs/settings.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# solutionFiles:
2+
# - ../../LSP.sln
3+
sourceFiles:
4+
- ../../src/**/{!.git,!bin,!obj,!packages,!*.Tests,}/**/*.cs

docs/theme/DocsTable.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Statiq.Common;
2+
using System.Collections.Generic;
3+
4+
namespace Generator
5+
{
6+
/// <summary>
7+
/// This model is used for the DocsTable partial that renders documents, titles, headers, and summaries as a table.
8+
/// </summary>
9+
public class DocsTable
10+
{
11+
public IList<IDocument> Docs { get; set; } = new List<IDocument>();
12+
public string Title { get; set; } = string.Empty;
13+
public string Header { get; set; } = string.Empty;
14+
public bool HasSummary { get; set; }
15+
public bool LinkTypeArguments { get; set; } = true;
16+
}
17+
}

docs/theme/Extensions.cs

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Net;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Microsoft.AspNetCore.Html;
8+
using Statiq.CodeAnalysis;
9+
using Statiq.Common;
10+
using Statiq.Html;
11+
12+
namespace Generator
13+
{
14+
/// <summary>
15+
/// Extensions used by the views.
16+
/// </summary>
17+
public static class Extensions
18+
{
19+
public static HtmlString Name(this IDocument document) => new HtmlString(FormatName(document.GetString(CodeAnalysisKeys.DisplayName)));
20+
21+
public static HtmlString GetTypeLink(this IExecutionContext context, IDocument document) => context.GetTypeLink(document, null, true);
22+
23+
public static HtmlString GetTypeLink(this IExecutionContext context, IDocument document, bool linkTypeArguments) => context.GetTypeLink(document, null, linkTypeArguments);
24+
25+
public static HtmlString GetTypeLink(this IExecutionContext context, IDocument document, string name) => context.GetTypeLink(document, name, true);
26+
27+
public static HtmlString GetTypeLink(this IExecutionContext context, IDocument document, string name, bool linkTypeArguments)
28+
{
29+
name = name ?? document.GetString(CodeAnalysisKeys.DisplayName);
30+
31+
// Link nullable types to their type argument
32+
if (document.GetString("Name") == "Nullable")
33+
{
34+
IDocument nullableType = document.GetDocumentList(CodeAnalysisKeys.TypeArguments)?.FirstOrDefault();
35+
if (nullableType != null)
36+
{
37+
return context.GetTypeLink(nullableType, name);
38+
}
39+
}
40+
41+
// If it wasn't nullable, format the name
42+
name = FormatName(name);
43+
44+
// Link the type and type parameters seperatly for generic types
45+
IReadOnlyList<IDocument> typeArguments = document.GetDocumentList(CodeAnalysisKeys.TypeArguments);
46+
if (typeArguments?.Count > 0)
47+
{
48+
// Link to the original definition of the generic type
49+
document = document.GetDocument(CodeAnalysisKeys.OriginalDefinition) ?? document;
50+
51+
if (linkTypeArguments)
52+
{
53+
// Get the type argument positions
54+
int begin = name.IndexOf("<wbr>&lt;") + 9;
55+
int openParen = name.IndexOf("&gt;<wbr>(");
56+
int end = name.LastIndexOf("&gt;<wbr>", openParen == -1 ? name.Length : openParen); // Don't look past the opening paren if there is one
57+
58+
// Remove existing type arguments and insert linked type arguments (do this first to preserve original indexes)
59+
if (end - begin > 0)
60+
{
61+
name = name
62+
.Remove(begin, end - begin)
63+
.Insert(begin, string.Join(", <wbr>", typeArguments.Select(x => context.GetTypeLink(x, true).Value)));
64+
65+
// Insert the link for the type
66+
if (!document.Destination.IsNull)
67+
{
68+
name = name.Insert(begin - 9, "</a>").Insert(0, $"<a href=\"{context.GetLink(document.Destination)}\">");
69+
}
70+
}
71+
72+
return new HtmlString(name);
73+
}
74+
}
75+
76+
// If it's a type parameter, create an anchor link to the declaring type's original definition
77+
if (document.GetString("Kind") == "TypeParameter")
78+
{
79+
IDocument declaringType = document.GetDocument(CodeAnalysisKeys.DeclaringType)?.GetDocument(CodeAnalysisKeys.OriginalDefinition);
80+
if (declaringType != null)
81+
{
82+
return new HtmlString(declaringType.Destination.IsNull
83+
? name
84+
: $"<a href=\"{context.GetLink(declaringType.Destination)}#typeparam-{document["Name"]}\">{name}</a>");
85+
}
86+
}
87+
88+
return new HtmlString(document.Destination.IsNull
89+
? name
90+
: $"<a href=\"{context.GetLink(document.Destination)}\">{name}</a>");
91+
}
92+
93+
// https://stackoverflow.com/a/3143036/807064
94+
private static IEnumerable<string> SplitAndKeep(this string s, params char[] delims)
95+
{
96+
int start = 0, index;
97+
98+
while ((index = s.IndexOfAny(delims, start)) != -1)
99+
{
100+
if (index - start > 0)
101+
{
102+
yield return s.Substring(start, index - start);
103+
}
104+
105+
yield return s.Substring(index, 1);
106+
start = index + 1;
107+
}
108+
109+
if (start < s.Length)
110+
{
111+
yield return s.Substring(start);
112+
}
113+
}
114+
115+
private static string FormatName(string name)
116+
{
117+
if (name == null)
118+
{
119+
return string.Empty;
120+
}
121+
122+
// Encode and replace .()<> with word break opportunities
123+
name = WebUtility.HtmlEncode(name)
124+
.Replace(".", "<wbr>.")
125+
.Replace("(", "<wbr>(")
126+
.Replace(")", ")<wbr>")
127+
.Replace(", ", ", <wbr>")
128+
.Replace("&lt;", "<wbr>&lt;")
129+
.Replace("&gt;", "&gt;<wbr>");
130+
131+
// Add additional break opportunities in long un-broken segments
132+
List<string> segments = name.Split(new[] { "<wbr>" }, StringSplitOptions.None).ToList();
133+
bool replaced = false;
134+
for (int c = 0; c < segments.Count; c++)
135+
{
136+
if (segments[c].Length > 20)
137+
{
138+
segments[c] = new string(segments[c]
139+
.SelectMany((x, i) => char.IsUpper(x) && i != 0 ? new[] { '<', 'w', 'b', 'r', '>', x } : new[] { x })
140+
.ToArray());
141+
replaced = true;
142+
}
143+
}
144+
145+
return replaced ? string.Join("<wbr>", segments) : name;
146+
}
147+
148+
/// <summary>
149+
/// Generates links to each heading on a page and returns a string containing all of the links.
150+
/// </summary>
151+
public static async Task<string> GenerateInfobarHeadingsAsync(this IExecutionContext context, IDocument document)
152+
{
153+
StringBuilder content = new StringBuilder();
154+
IReadOnlyList<IDocument> headings = document.GetDocumentList(HtmlKeys.Headings);
155+
if (headings != null)
156+
{
157+
foreach (IDocument heading in headings)
158+
{
159+
string id = heading.GetString(HtmlKeys.HeadingId);
160+
if (id != null)
161+
{
162+
content.AppendLine($"<p><a href=\"#{id}\">{await heading.GetContentStringAsync()}</a></p>");
163+
}
164+
}
165+
}
166+
if (content.Length > 0)
167+
{
168+
content.Insert(0, "<h6>On This Page</h6>");
169+
content.AppendLine("<hr class=\"infobar-hidden\" />");
170+
return content.ToString();
171+
}
172+
return null;
173+
}
174+
}
175+
}

0 commit comments

Comments
 (0)