|
| 1 | +/* |
| 2 | + * PicoXLSX is a small .NET library to generate XLSX (Microsoft Excel 2007 or newer) files in an easy and native way |
| 3 | + * Copyright Raphael Stoeckli © 2026 |
| 4 | + * This library is licensed under the MIT License. |
| 5 | + * You find a copy of the license in project folder or on: http://opensource.org/licenses/MIT |
| 6 | + */ |
| 7 | + |
| 8 | +using System; |
| 9 | +using System.Collections.Generic; |
| 10 | +using System.Text; |
| 11 | +using Docs.IndexGenerator.Models; |
| 12 | + |
| 13 | +namespace Docs.IndexGenerator.Generation |
| 14 | +{ |
| 15 | + /// <summary> |
| 16 | + /// Generates an llms.txt file following the convention at https://llmstxt.org/. |
| 17 | + /// Layout: H1 project title, blockquote summary, then linked sections. |
| 18 | + /// </summary> |
| 19 | + internal static class LlmsTxtGenerator |
| 20 | + { |
| 21 | + public static string Build(RootConfig root, MetaPackageConfig meta, PluginConfig plugins) |
| 22 | + { |
| 23 | + var sb = new StringBuilder(); |
| 24 | + |
| 25 | + sb.Append("# ").AppendLine(root.ProjectName); |
| 26 | + sb.AppendLine(); |
| 27 | + sb.Append("> ").AppendLine(root.LlmsSummary); |
| 28 | + sb.AppendLine(); |
| 29 | + |
| 30 | + sb.AppendLine("## Packages"); |
| 31 | + sb.AppendLine(); |
| 32 | + sb.Append("Meta package **").Append(meta.PackageName).Append(" v").Append(meta.Version) |
| 33 | + .AppendLine("** bundles all of the below."); |
| 34 | + sb.AppendLine(); |
| 35 | + |
| 36 | + string metaUrl = !string.IsNullOrEmpty(meta.NuGetUrl) |
| 37 | + ? meta.NuGetUrl |
| 38 | + : root.RepositoryUrl; |
| 39 | + sb.Append("- [").Append(meta.PackageName).Append("](").Append(metaUrl).Append("): ") |
| 40 | + .AppendLine(meta.Description ?? string.Empty); |
| 41 | + |
| 42 | + List<DocEntry> nonBundledEntries = new List<DocEntry>(); |
| 43 | + |
| 44 | + foreach (DocEntry e in plugins.Entries) |
| 45 | + { |
| 46 | + if (!e.Bundled) |
| 47 | + { |
| 48 | + nonBundledEntries.Add(e); |
| 49 | + continue; |
| 50 | + } |
| 51 | + string url = !string.IsNullOrEmpty(e.NuGetUrl) |
| 52 | + ? e.NuGetUrl |
| 53 | + : (e.Repository ?? string.Empty); |
| 54 | + string description = e.Description ?? string.Empty; |
| 55 | + string bundledTag = e.Bundled ? " (bundled)" : string.Empty; |
| 56 | + sb.Append("- [").Append(e.Id).Append("](").Append(url).Append("): ") |
| 57 | + .Append(description).AppendLine(bundledTag); |
| 58 | + } |
| 59 | + |
| 60 | + if (nonBundledEntries.Count > 0) |
| 61 | + { |
| 62 | + sb.AppendLine(); |
| 63 | + sb.AppendLine("Other available packages (not bundled in meta package):"); |
| 64 | + sb.AppendLine(); |
| 65 | + foreach (DocEntry e in nonBundledEntries) |
| 66 | + { |
| 67 | + string url = !string.IsNullOrEmpty(e.NuGetUrl) |
| 68 | + ? e.NuGetUrl |
| 69 | + : (e.Repository ?? string.Empty); |
| 70 | + string description = e.Description ?? string.Empty; |
| 71 | + sb.Append("- [").Append(e.Id).Append("](").Append(url).Append("): ") |
| 72 | + .Append(description).AppendLine(); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + sb.AppendLine(); |
| 77 | + sb.AppendLine("## API Documentation"); |
| 78 | + sb.AppendLine(); |
| 79 | + sb.Append("- Combined documentation portal: ").AppendLine(root.ApiDocsUrl); |
| 80 | + foreach (var e in plugins.Entries) |
| 81 | + { |
| 82 | + if (!string.IsNullOrEmpty(e.ApiDocsUrl)) |
| 83 | + { |
| 84 | + sb.Append("- ").Append(e.Id).Append(": ").AppendLine(e.ApiDocsUrl); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + sb.AppendLine(); |
| 89 | + sb.AppendLine("## Source"); |
| 90 | + sb.AppendLine(); |
| 91 | + sb.Append("- Primary repository: ").AppendLine(root.RepositoryUrl); |
| 92 | + foreach (var e in plugins.Entries) |
| 93 | + { |
| 94 | + if (!string.IsNullOrEmpty(e.Repository) && |
| 95 | + !string.Equals(e.Repository, root.RepositoryUrl, StringComparison.OrdinalIgnoreCase)) |
| 96 | + { |
| 97 | + sb.Append("- ").Append(e.Id).Append(" (external): ").AppendLine(e.Repository); |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + sb.AppendLine(); |
| 102 | + sb.AppendLine("## Demos"); |
| 103 | + sb.AppendLine(); |
| 104 | + sb.Append("- Repository with running demo use cases: ").AppendLine(root.DemoRepositoryUrl); |
| 105 | + sb.Append("- Direct folder URL with use cases for ").Append(root.ProjectName).Append(": ").AppendLine(root.DemoRepositoryUseCaseUrl); |
| 106 | + |
| 107 | + sb.AppendLine(); |
| 108 | + sb.AppendLine("## Notes"); |
| 109 | + sb.AppendLine(); |
| 110 | + sb.AppendLine("- Docs.IndexGenerator/ is a build utility and not part of the public API."); |
| 111 | + sb.AppendLine("- This file is generated automatically on build from Docs.IndexGenerator/Config/*.json — do not edit by hand."); |
| 112 | + |
| 113 | + return sb.ToString(); |
| 114 | + } |
| 115 | + } |
| 116 | +} |
0 commit comments