mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-08-03 10:27:58 +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:
@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Statiq.Common;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Docs.Shortcodes
|
||||
{
|
||||
@ -8,7 +7,6 @@ namespace Docs.Shortcodes
|
||||
{
|
||||
public override ShortcodeResult Execute(KeyValuePair<string, string>[] args, string content, IDocument document, IExecutionContext context)
|
||||
{
|
||||
|
||||
return $"<div class=\"alert-warning\">{content}</div>";
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Statiq.Common;
|
||||
using System.Xml.Linq;
|
||||
using Docs.Extensions;
|
||||
|
||||
namespace Docs.Shortcodes
|
||||
{
|
||||
|
@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Statiq.Common;
|
||||
@ -10,8 +9,6 @@ namespace Docs.Shortcodes
|
||||
{
|
||||
public class ColorTableShortcode : SyncShortcode
|
||||
{
|
||||
private const string ColorStyle = "display: inline-block;width: 60px; height: 15px;";
|
||||
|
||||
public override ShortcodeResult Execute(KeyValuePair<string, string>[] args, string content, IDocument document, IExecutionContext context)
|
||||
{
|
||||
// Get the definition.
|
||||
|
@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Statiq.Common;
|
||||
@ -31,7 +30,6 @@ namespace Docs.Shortcodes
|
||||
|
||||
foreach (var emoji in emojis)
|
||||
{
|
||||
var code = emoji.Code.Replace("U+0000", "U+").Replace("U+000", "U+");
|
||||
var icon = $"&#x{emoji.Code.Replace("U+", string.Empty)};";
|
||||
|
||||
var row = new XElement("tr", new XAttribute("class", "search-row"));
|
||||
|
43
docs/src/Shortcodes/ExampleSnippet.cs
Normal file
43
docs/src/Shortcodes/ExampleSnippet.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Docs.Extensions;
|
||||
using Docs.Utilities;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Statiq.CodeAnalysis;
|
||||
using Statiq.Common;
|
||||
|
||||
namespace Docs.Shortcodes;
|
||||
|
||||
public class ExampleSnippet : Shortcode
|
||||
{
|
||||
protected const string Solution = nameof(Solution);
|
||||
protected const string Project = nameof(Project);
|
||||
protected const string Symbol = nameof(Symbol);
|
||||
protected const string BodyOnly = nameof(BodyOnly);
|
||||
|
||||
public override async Task<ShortcodeResult> ExecuteAsync(KeyValuePair<string, string>[] args, string content,
|
||||
IDocument document, IExecutionContext context)
|
||||
{
|
||||
var props = args.ToDictionary(Solution, Project, Symbol, BodyOnly);
|
||||
var symbolName = props.GetString(Symbol);
|
||||
var bodyOnly = props.Get<bool?>(BodyOnly) ?? symbolName.StartsWith("m:", StringComparison.InvariantCultureIgnoreCase);
|
||||
|
||||
if (!context.TryGetCommentIdDocument(symbolName, out var apiDocument, out _))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var options = HighlightService.HighlightOption.All;
|
||||
if (bodyOnly)
|
||||
{
|
||||
options = HighlightService.HighlightOption.Body;
|
||||
}
|
||||
|
||||
var comp = apiDocument.Get<Compilation>(CodeAnalysisKeys.Compilation);
|
||||
var symbol = apiDocument.Get<ISymbol>(CodeAnalysisKeys.Symbol);
|
||||
var highlightElement = await HighlightService.Highlight(comp, symbol, options);
|
||||
ShortcodeResult shortcodeResult = $"<pre><code>{highlightElement}</code></pre>";
|
||||
return shortcodeResult;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user