mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-09-19 10:52:42 +08:00
Docs redesign (#728)
* Adding a dark mode * Adding reference for types to summary pages * Adding API Reference * Adding modifiers to methods/fields/etc * Minimizing files input * Caching a lot of the output pages * Cache only for each execution * Adding API references to existing docs
This commit is contained in:
151
docs/src/Pipelines/CodePipeline.cs
Normal file
151
docs/src/Pipelines/CodePipeline.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using Docs.Utilities;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Statiq.CodeAnalysis;
|
||||
using Statiq.Common;
|
||||
using Statiq.Core;
|
||||
using Statiq.Web;
|
||||
using Statiq.Web.Pipelines;
|
||||
|
||||
namespace Docs.Pipelines;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Loads source files.
|
||||
/// </summary>
|
||||
public class Code : Pipeline
|
||||
{
|
||||
public Code()
|
||||
{
|
||||
InputModules = new ModuleList(
|
||||
new ReadFiles(
|
||||
Config.FromSettings(settings
|
||||
=> settings.GetList<string>(Constants.SourceFiles).AsEnumerable())));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads source files.
|
||||
/// </summary>
|
||||
public class ExampleCode : Pipeline
|
||||
{
|
||||
public ExampleCode()
|
||||
{
|
||||
Dependencies.Add(nameof(Code));
|
||||
|
||||
InputModules = new ModuleList(
|
||||
new ReadFiles(
|
||||
Config.FromSettings(settings
|
||||
=> settings.GetList<string>(Constants.ExampleSourceFiles).AsEnumerable())));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses Roslyn to analyze any source files loaded in the previous
|
||||
/// pipeline along with any specified assemblies. This pipeline
|
||||
/// results in documents that represent Roslyn symbols.
|
||||
/// </summary>
|
||||
public class ExampleSyntax : Pipeline
|
||||
{
|
||||
public ExampleSyntax()
|
||||
{
|
||||
Dependencies.Add(nameof(ExampleCode));
|
||||
DependencyOf.Add(nameof(Content));
|
||||
|
||||
ProcessModules = new ModuleList
|
||||
{
|
||||
new ConcatDocuments(nameof(Code)),
|
||||
new ConcatDocuments(nameof(ExampleCode)),
|
||||
new CacheDocuments(
|
||||
new AnalyzeCSharp()
|
||||
.WhereNamespaces(true)
|
||||
.WherePublic()
|
||||
.WithCssClasses("code", "cs")
|
||||
.WithDestinationPrefix("syntax")
|
||||
.WithAssemblySymbols()
|
||||
// we need to load Spectre.Console for compiling, but we don't need to process it in Statiq
|
||||
.WhereNamespaces(i => !i.StartsWith("Spectre.Console"))
|
||||
.WithImplicitInheritDoc(false),
|
||||
new ExecuteConfig(Config.FromDocument((doc, _) =>
|
||||
{
|
||||
// Add metadata
|
||||
var metadataItems = new MetadataItems
|
||||
{
|
||||
// Calculate an xref that includes a "api-" prefix to avoid collisions
|
||||
{ WebKeys.Xref, "syntax-" + doc.GetString(CodeAnalysisKeys.CommentId) },
|
||||
};
|
||||
|
||||
var contentProvider = doc.ContentProvider;
|
||||
return doc.Clone(metadataItems, contentProvider);
|
||||
}))).WithoutSourceMapping()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates API documentation pipeline.
|
||||
/// </summary>
|
||||
public class Api : Pipeline
|
||||
{
|
||||
public Api()
|
||||
{
|
||||
Dependencies.Add(nameof(Code));
|
||||
DependencyOf.Add(nameof(Content));
|
||||
|
||||
ProcessModules = new ModuleList
|
||||
{
|
||||
new ConcatDocuments(nameof(Code)),
|
||||
new CacheDocuments(
|
||||
new AnalyzeCSharp()
|
||||
.WhereNamespaces(ns => ns.StartsWith("Spectre.Console") && !ns.Contains("Analyzer") &&
|
||||
!ns.Contains("Testing") && !ns.Contains("Examples"))
|
||||
.WherePublic(true)
|
||||
.WithCssClasses("code", "cs")
|
||||
.WithDestinationPrefix("api")
|
||||
.WithAssemblySymbols()
|
||||
.WithImplicitInheritDoc(false),
|
||||
new ExecuteConfig(Config.FromDocument((doc, ctx) =>
|
||||
{
|
||||
// Calculate a type name to link lookup for auto linking
|
||||
string name = null;
|
||||
|
||||
var kind = doc.GetString(CodeAnalysisKeys.Kind);
|
||||
switch (kind)
|
||||
{
|
||||
case "NamedType":
|
||||
name = doc.GetString(CodeAnalysisKeys.DisplayName);
|
||||
break;
|
||||
case "Method":
|
||||
var containingType = doc.GetDocument(CodeAnalysisKeys.ContainingType);
|
||||
if (containingType != null)
|
||||
{
|
||||
name =
|
||||
$"{containingType.GetString(CodeAnalysisKeys.DisplayName)}.{doc.GetString(CodeAnalysisKeys.DisplayName)}";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (name != null)
|
||||
{
|
||||
var typeNameLinks = ctx.GetRequiredService<TypeNameLinks>();
|
||||
typeNameLinks.Links.AddOrUpdate(WebUtility.HtmlEncode(name), ctx.GetLink(doc),
|
||||
(_, _) => string.Empty);
|
||||
}
|
||||
|
||||
// Add metadata
|
||||
var metadataItems = new MetadataItems
|
||||
{
|
||||
{ WebKeys.Xref, doc.GetString(CodeAnalysisKeys.CommentId) },
|
||||
{ WebKeys.Layout, "api/_layout.cshtml" },
|
||||
{ Constants.Hidden, true }
|
||||
};
|
||||
|
||||
var contentProvider = doc.ContentProvider.CloneWithMediaType(MediaTypes.Html);
|
||||
metadataItems.Add(WebKeys.ContentType, ContentType.Content);
|
||||
return doc.Clone(metadataItems, contentProvider);
|
||||
}))).WithoutSourceMapping()
|
||||
};
|
||||
}
|
||||
}
|
@@ -1,5 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Docs.Models;
|
||||
using Statiq.Common;
|
||||
@@ -14,7 +12,7 @@ namespace Docs.Pipelines
|
||||
InputModules = new ModuleList
|
||||
{
|
||||
new ExecuteConfig(
|
||||
Config.FromContext(ctx => {
|
||||
Config.FromContext(_ => {
|
||||
return new ReadWeb(Constants.Colors.Url);
|
||||
}))
|
||||
};
|
||||
@@ -22,9 +20,9 @@ namespace Docs.Pipelines
|
||||
ProcessModules = new ModuleList
|
||||
{
|
||||
new ExecuteConfig(
|
||||
Config.FromDocument(async (doc, ctx) =>
|
||||
Config.FromDocument(async (doc, _) =>
|
||||
{
|
||||
var data = Color.Parse(await doc.GetContentStringAsync()).ToList();
|
||||
var data = Color.Parse(await doc.GetContentStringAsync()).ToList();
|
||||
return data.ToDocument(Constants.Colors.Root);
|
||||
}))
|
||||
};
|
||||
|
@@ -1,10 +1,9 @@
|
||||
using Statiq.Common;
|
||||
using Statiq.Core;
|
||||
using Statiq.Web.GitHub;
|
||||
|
||||
namespace Docs.Pipelines
|
||||
{
|
||||
public class DeploymentPipeline : Pipeline
|
||||
public class DeploymentPipeline : Statiq.Core.Pipeline
|
||||
{
|
||||
public DeploymentPipeline()
|
||||
{
|
||||
|
@@ -1,4 +1,3 @@
|
||||
using System.Collections.Generic;
|
||||
using Docs.Models;
|
||||
using Docs.Modules;
|
||||
using Statiq.Common;
|
||||
@@ -13,7 +12,7 @@ namespace Docs.Pipelines
|
||||
InputModules = new ModuleList
|
||||
{
|
||||
new ExecuteConfig(
|
||||
Config.FromContext(ctx => {
|
||||
Config.FromContext(_ => {
|
||||
return new ReadEmbedded(
|
||||
typeof(EmojiPipeline).Assembly,
|
||||
"Docs/src/Data/emojis.json");
|
||||
@@ -23,7 +22,7 @@ namespace Docs.Pipelines
|
||||
ProcessModules = new ModuleList
|
||||
{
|
||||
new ExecuteConfig(
|
||||
Config.FromDocument(async (doc, ctx) =>
|
||||
Config.FromDocument(async (doc, _) =>
|
||||
{
|
||||
var data = Emoji.Parse(await doc.GetContentStringAsync());
|
||||
return data.ToDocument(Constants.Emojis.Root);
|
||||
|
Reference in New Issue
Block a user