|
| 1 | +/* |
| 2 | + * NanoXLSX is a small .NET library to generate and read 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.Text; |
| 10 | +using Docs.IndexGenerator.Models; |
| 11 | +using Docs.IndexGenerator.Util; |
| 12 | + |
| 13 | +namespace Docs.IndexGenerator.Generation |
| 14 | +{ |
| 15 | + internal static class IndexHtmlGenerator |
| 16 | + { |
| 17 | + public static string Build(RootConfig root, MetaPackageConfig meta, PluginConfig plugins) |
| 18 | + { |
| 19 | + return $@" |
| 20 | +<!doctype html> |
| 21 | +<html lang=""en""> |
| 22 | + <head> |
| 23 | + <meta charset=""utf-8""> |
| 24 | + <meta name=""viewport"" content=""width=device-width,initial-scale=1""> |
| 25 | + <title>{HtmlEncoder.Escape(root.ProjectName)} — Documentation</title> |
| 26 | + <link rel=""stylesheet"" href=""style.css""> |
| 27 | + </head> |
| 28 | + <body> |
| 29 | + <main> |
| 30 | + <header> |
| 31 | + <h1> |
| 32 | + <img src=""NanoXLSX.png"" |
| 33 | + alt=""NanoXLSX"" |
| 34 | + style=""height:48px; vertical-align:middle; margin-right:10px;""> |
| 35 | + {HtmlEncoder.Escape(root.ProjectName)} |
| 36 | + </h1> |
| 37 | +
|
| 38 | + <p>{HtmlEncoder.Escape(root.BaseDescription)}</p> |
| 39 | + <p>{HtmlEncoder.Escape(root.RootDescription)}</p> |
| 40 | +
|
| 41 | + <hr> |
| 42 | +
|
| 43 | + <h2>Meta Package v{HtmlEncoder.Escape(meta.Version)}</h2> |
| 44 | + <section> |
| 45 | + {RenderMetaPackageItem(meta, root)} |
| 46 | + <p>There is no documentation for the meta package. Please see the section <b>Dependency Package Documentation</b> for the complete API documentation.</p> |
| 47 | + </section> |
| 48 | +
|
| 49 | + <p class=""version"">Version {HtmlEncoder.Escape(meta.Version)}</p> |
| 50 | + </header> |
| 51 | +
|
| 52 | + <hr> |
| 53 | +
|
| 54 | + <section> |
| 55 | + <h2>Dependency Package Documentation</h2> |
| 56 | + <table class=""list""> |
| 57 | + <tr> |
| 58 | + <td>Package</td><td>Description</td><td>Bundled</td><td>Repository</td> |
| 59 | + </tr> |
| 60 | + {RenderListItems(plugins)} |
| 61 | + </table> |
| 62 | + </section> |
| 63 | + </main> |
| 64 | + </body> |
| 65 | +</html>"; |
| 66 | + } |
| 67 | + |
| 68 | + private static string RenderListItems(PluginConfig cfg) |
| 69 | + { |
| 70 | + var sb = new StringBuilder(); |
| 71 | + foreach (var e in cfg.Entries) |
| 72 | + { |
| 73 | + string repoUrl = Uri.EscapeUriString(e.Repository ?? string.Empty); |
| 74 | + string docUrl = $"{Uri.EscapeUriString(e.Path)}/index.html"; |
| 75 | + sb.AppendLine(" <tr>"); |
| 76 | + sb.AppendLine($" <td><a href=\"{docUrl}\"><strong>{HtmlEncoder.Escape(e.Title)}</strong></a></td>"); |
| 77 | + sb.AppendLine($" <td>{HtmlEncoder.Escape(e.Description ?? "")}</td>"); |
| 78 | + sb.AppendLine($" <td>{HtmlEncoder.Escape(e.Bundled.ToString())}</td>"); |
| 79 | + sb.AppendLine($" <td><a href=\"{repoUrl}\" target=\"_blank\" rel=\"noopener\">{HtmlEncoder.Escape(e.RepositoryDisplayName ?? string.Empty)}</a></td>"); |
| 80 | + sb.AppendLine(" </tr>"); |
| 81 | + } |
| 82 | + return sb.ToString(); |
| 83 | + } |
| 84 | + |
| 85 | + private static string RenderMetaPackageItem(MetaPackageConfig meta, RootConfig root) |
| 86 | + { |
| 87 | + var sb = new StringBuilder(); |
| 88 | + sb.AppendLine("<ul class=\"list\">"); |
| 89 | + string description = StripBaseDescriptionPrefix(root, meta.Description); |
| 90 | + sb.AppendLine($" <li><strong>{HtmlEncoder.Escape(meta.PackageName)}</strong> — {HtmlEncoder.Escape(description ?? "")}</li>"); |
| 91 | + sb.AppendLine("</ul>"); |
| 92 | + return sb.ToString(); |
| 93 | + } |
| 94 | + |
| 95 | + private static string StripBaseDescriptionPrefix(RootConfig root, string input) |
| 96 | + { |
| 97 | + if (string.IsNullOrEmpty(input)) |
| 98 | + { |
| 99 | + return input; |
| 100 | + } |
| 101 | + if (input.StartsWith(root.BaseDescription, StringComparison.Ordinal)) |
| 102 | + { |
| 103 | + return input[root.BaseDescription.Length..]; |
| 104 | + } |
| 105 | + return input; |
| 106 | + } |
| 107 | + } |
| 108 | +} |
0 commit comments