Skip to content

Commit 0ad32e1

Browse files
committed
Fixed some bugs with API doc generation & removed some classes from automatic API doc generation:
- Added api doc generation multithreading - Improved xref url fixing - Docs are a little prettier
1 parent 88bff58 commit 0ad32e1

4 files changed

Lines changed: 208 additions & 48 deletions

File tree

StarlightDocNet/MDStringBuilder.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ namespace StarlightDocNet;
77
public class MDStringBuilder
88
{
99
protected readonly StringBuilder sb = new();
10-
public readonly string localURLRoot;
10+
public readonly string localURLRoot = "/";
11+
public readonly HashSet<string> knownPages = [];
1112

1213
public readonly static MDStringBuilder Shared = new();
1314

1415
public MDStringBuilder()
1516
{
16-
localURLRoot = "/";
17+
1718
}
1819

19-
public MDStringBuilder(string localURLRoot)
20+
public MDStringBuilder(string localURLRoot, HashSet<string> knownPages)
2021
{
2122
this.localURLRoot = localURLRoot;
23+
this.knownPages = knownPages;
2224
}
2325

2426
public MDStringBuilder Clear()
@@ -40,6 +42,12 @@ public MDStringBuilder Add(char c)
4042
return this;
4143
}
4244

45+
public MDStringBuilder Add(ReadOnlySpan<char> c)
46+
{
47+
sb.Append(c);
48+
return this;
49+
}
50+
4351
public MDStringBuilder Add(string? s)
4452
{
4553
if (s != null)
@@ -65,6 +73,18 @@ public MDStringBuilder Add(float x)
6573
return this;
6674
}
6775

76+
public MDStringBuilder Line()
77+
{
78+
sb.AppendLine();
79+
return this;
80+
}
81+
82+
public MDStringBuilder Line(ReadOnlySpan<char> s)
83+
{
84+
sb.Append(s).AppendLine();
85+
return this;
86+
}
87+
6888
public MDStringBuilder Line(string s)
6989
{
7090
sb.AppendLine(s);
@@ -175,14 +195,16 @@ public MDStringBuilder Image(string img, string alt, string url)
175195
return this;
176196
}
177197

178-
public MDStringBuilder MetaHeader(string title, string? description = null, int? order = null)
198+
public MDStringBuilder MetaHeader(string title, string? description = null, int? order = null, string? sidebarTitle = null)
179199
{
180200
sb.AppendLine("---");
181201
sb.Append("title: ").AppendLine(title);
182202
if (description != null)
183203
sb.Append("description: ").AppendLine(description);
184204
if (order != null)
185205
sb.Append("order: ").AppendLine(order.Value.ToString());
206+
if (sidebarTitle != null)
207+
sb.AppendLine("sidebar: ").Append(" label: ").AppendLine(sidebarTitle);
186208
sb.AppendLine("---").AppendLine();
187209
return this;
188210
}

StarlightDocNet/Program.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,26 @@ static void Main(string[] args)
1515
string dstPath = args[1];
1616

1717
Stopwatch sw = Stopwatch.StartNew();
18-
foreach (var path in Directory.EnumerateFiles(srcPath))
18+
Log("Preparing to process files...");
19+
var srcFiles = Directory.EnumerateFiles(srcPath).ToArray();
20+
21+
var apiDocRootInd = dstPath.LastIndexOf("docs");
22+
var apiDocRoot = "/";
23+
if (apiDocRootInd != -1)
24+
apiDocRoot = dstPath[(apiDocRootInd + 4)..].Replace(Path.DirectorySeparatorChar, '/');
25+
if (!apiDocRoot.EndsWith('/'))
26+
apiDocRoot += '/';
27+
28+
var srcFileNames = srcFiles.Select(x => Path.GetFileNameWithoutExtension(x)).ToHashSet();
29+
30+
Parallel.ForEach(srcFiles, path =>
1931
{
20-
YML2MD yml2md = new();
21-
yml2md.Process(path, dstPath);
22-
}
32+
YML2MD.Process(path, dstPath, apiDocRoot, srcFileNames);
33+
});
34+
//foreach (var path in srcFiles)
35+
// YML2MD.Process(path, dstPath, dstPath, srcFileNames);
2336
sw.Stop();
24-
Log($"Completed it {sw}!");
37+
Log($"Completed in {sw}!");
2538
}
2639

2740
public static void Assert(bool condition, string? msg = null, [CallerArgumentExpression(nameof(condition))] string? expr = null, [CallerMemberName] string caller = "")

0 commit comments

Comments
 (0)