Vibe documents
This commit is contained in:
@@ -197,6 +197,78 @@ deckWriter.WriteLine(" ];");
|
||||
deckWriter.WriteLine("}");
|
||||
|
||||
Console.WriteLine($"Generated {decks.Count} decks in {deckGeneratedFile}");
|
||||
|
||||
// ── Docs ──
|
||||
var excludedCategories = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
"Agent", "Immortalized", "Spell", "Token", "Decks", "Deck"
|
||||
};
|
||||
|
||||
var docs = new List<DocData>();
|
||||
foreach (var file in mdFiles)
|
||||
{
|
||||
var content = Encoding.UTF8.GetString(File.ReadAllBytes(file));
|
||||
Dictionary<string, string> yaml = [];
|
||||
var body = content;
|
||||
|
||||
if (content.StartsWith("---"))
|
||||
{
|
||||
var endIndex = content.IndexOf("---", 3, StringComparison.Ordinal);
|
||||
if (endIndex >= 0)
|
||||
{
|
||||
var frontmatter = content[3..endIndex].Trim().Replace("\r\n", "\n").Replace("\r", "\n");
|
||||
yaml = ParseYaml(frontmatter);
|
||||
body = content[(endIndex + 3)..].Trim();
|
||||
}
|
||||
}
|
||||
|
||||
var category = yaml.GetValueOrDefault("category") ?? Path.GetFileName(Path.GetDirectoryName(file)) ?? "";
|
||||
if (excludedCategories.Contains(category)) continue;
|
||||
|
||||
// Also exclude files that look like base templates
|
||||
var fileName = Path.GetFileName(file);
|
||||
if (fileName.StartsWith("_")) continue;
|
||||
|
||||
docs.Add(new DocData
|
||||
{
|
||||
Title = Path.GetFileNameWithoutExtension(file),
|
||||
Category = category,
|
||||
Content = body,
|
||||
Frontmatter = yaml
|
||||
});
|
||||
}
|
||||
|
||||
var docGeneratedFile = Path.Combine(repoRoot, "Chrono", "Shared", "Generated", "Docs.g.cs");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(docGeneratedFile)!);
|
||||
using var docWriter = new StreamWriter(docGeneratedFile, false, Encoding.UTF8);
|
||||
docWriter.WriteLine("// <auto-generated/>");
|
||||
docWriter.WriteLine("#nullable enable");
|
||||
docWriter.WriteLine();
|
||||
docWriter.WriteLine("namespace Chrono.Model;");
|
||||
docWriter.WriteLine();
|
||||
docWriter.WriteLine("public static class DocDatabase");
|
||||
docWriter.WriteLine("{");
|
||||
docWriter.WriteLine(" public static readonly System.Collections.Generic.List<DocData> Docs =");
|
||||
docWriter.WriteLine(" [");
|
||||
|
||||
for (var i = 0; i < docs.Count; i++)
|
||||
{
|
||||
var d = docs[i];
|
||||
docWriter.WriteLine(" new()");
|
||||
docWriter.WriteLine(" {");
|
||||
WriteProp(docWriter, "Title", d.Title, 3);
|
||||
WriteProp(docWriter, "Category", d.Category, 3);
|
||||
WriteStrProp(docWriter, "Content", d.Content, 3);
|
||||
WriteDictProp(docWriter, "Frontmatter", d.Frontmatter, 3);
|
||||
var comma = i < docs.Count - 1 ? "," : "";
|
||||
docWriter.WriteLine($" }}{comma}");
|
||||
}
|
||||
|
||||
docWriter.WriteLine(" ];");
|
||||
docWriter.WriteLine("}");
|
||||
|
||||
Console.WriteLine($"Generated {docs.Count} docs in {docGeneratedFile}");
|
||||
|
||||
return 0;
|
||||
|
||||
// --- Helpers ---
|
||||
@@ -419,6 +491,17 @@ static void WriteListProp(StreamWriter w, string name, List<string>? values, int
|
||||
w.WriteLine($"{pad}],");
|
||||
}
|
||||
|
||||
static void WriteDictProp(StreamWriter w, string name, Dictionary<string, string>? values, int indent)
|
||||
{
|
||||
if (values == null || values.Count == 0) return;
|
||||
var pad = new string(' ', indent * 4);
|
||||
w.WriteLine($"{pad}{name} = new()");
|
||||
w.WriteLine($"{pad}{{");
|
||||
foreach (var (k, v) in values)
|
||||
w.WriteLine($"{pad} {{ {ToLiteral(k)}, {ToLiteral(v)} }},");
|
||||
w.WriteLine($"{pad}}},");
|
||||
}
|
||||
|
||||
static string ToLiteral(string? s)
|
||||
{
|
||||
if (s == null) return "null";
|
||||
|
||||
Reference in New Issue
Block a user