|
| 1 | +namespace Netdocs.Cli; |
| 2 | + |
| 3 | +/// <summary> |
| 4 | +/// <c>netdocs new</c> — scaffolds an annotated <c>appsettings.json</c> with every common option, |
| 5 | +/// sane defaults, and inline links back to the docs site. Comments and trailing commas are legal |
| 6 | +/// because <see cref="Netdocs.Core.Configuration.JsonConfigLoader"/> parses with |
| 7 | +/// <c>JsonCommentHandling.Skip</c> / <c>AllowTrailingCommas</c>. |
| 8 | +/// </summary> |
| 9 | +internal static class NewCommand |
| 10 | +{ |
| 11 | + private const string DocsBase = "https://xtremeownage.github.io/Netdocs"; |
| 12 | + |
| 13 | + public static async Task<int> RunAsync(string[] args) |
| 14 | + { |
| 15 | + // netdocs new [path/to/appsettings.json] [--force] |
| 16 | + var target = args.Skip(1).FirstOrDefault(a => !a.StartsWith('-')) |
| 17 | + ?? Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"); |
| 18 | + target = Path.GetFullPath(target); |
| 19 | + var force = args.Contains("--force"); |
| 20 | + |
| 21 | + if (File.Exists(target) && !force) |
| 22 | + { |
| 23 | + Console.Error.WriteLine($"Refusing to overwrite existing {target}. Pass --force to replace it."); |
| 24 | + return 1; |
| 25 | + } |
| 26 | + |
| 27 | + Directory.CreateDirectory(Path.GetDirectoryName(target)!); |
| 28 | + await File.WriteAllTextAsync(target, Template); |
| 29 | + Console.WriteLine($"Wrote annotated config -> {target}"); |
| 30 | + Console.WriteLine("Edit the values (siteName, siteUrl, repoUrl…), add your docs/ pages, then run: netdocs build"); |
| 31 | + return 0; |
| 32 | + } |
| 33 | + |
| 34 | + private static readonly string Template = $$""" |
| 35 | +{ |
| 36 | + // Netdocs configuration. This file is JSONC: // comments and trailing commas are allowed. |
| 37 | + // Full reference: {{DocsBase}}/reference/configuration/ |
| 38 | + "Logging": { |
| 39 | + "LogLevel": { "Default": "Information" } |
| 40 | + }, |
| 41 | +
|
| 42 | + "Netdocs": { |
| 43 | + // --- Site identity --------------------------------------------------------------- |
| 44 | + "siteName": "My Project", |
| 45 | + "siteUrl": "https://example.github.io/my-project/", // used for absolute URLs, sitemap, feeds |
| 46 | + "siteAuthor": "Your Name", |
| 47 | + "siteDescription": "Documentation for My Project.", |
| 48 | + "copyright": "© 2025 Your Name", |
| 49 | +
|
| 50 | + // Repo links power the header icon and the per-page Edit/View buttons. |
| 51 | + "repoUrl": "https://github.com/you/my-project", |
| 52 | + "repoName": "you/my-project", |
| 53 | + "editUri": "edit/main/docs/", // appended to repoUrl for the "Edit this page" button |
| 54 | +
|
| 55 | + "docsDir": "docs", // source markdown folder |
| 56 | + "siteDir": "site", // build output folder |
| 57 | +
|
| 58 | + // --- Theme ----------------------------------------------------------------------- |
| 59 | + // Reference: {{DocsBase}}/reference/theme/ |
| 60 | + "theme": { |
| 61 | + "name": "material", |
| 62 | + "language": "en", |
| 63 | + // "logo": "assets/logo.svg", |
| 64 | + // "favicon": "assets/favicon.png", |
| 65 | + // "customDir": "overrides", // drop-in template/partial overrides (Scriban) |
| 66 | + "highlight": "highlightjs", // "highlightjs" | "none" | custom (bring your own) |
| 67 | + "features": [ |
| 68 | + "navigation.instant", |
| 69 | + "navigation.tabs", |
| 70 | + "navigation.sections", |
| 71 | + "navigation.top", |
| 72 | + "navigation.footer", |
| 73 | + "navigation.indexes", |
| 74 | + // "navigation.path", // breadcrumbs |
| 75 | + "toc.follow", |
| 76 | + "content.code.copy", |
| 77 | + "content.code.annotate", |
| 78 | + "content.tooltips", |
| 79 | + "content.footnote.tooltips", |
| 80 | + "search.highlight", |
| 81 | + "search.suggest", |
| 82 | + "content.action.edit", // requires editUri above |
| 83 | + "content.action.view" |
| 84 | + ], |
| 85 | + // Light/dark palette with a header toggle. |
| 86 | + "palette": [ |
| 87 | + { "media": "(prefers-color-scheme: light)", "scheme": "default", "primary": "indigo", "accent": "indigo", |
| 88 | + "toggleIcon": "material/brightness-7", "toggleName": "Switch to dark mode" }, |
| 89 | + { "media": "(prefers-color-scheme: dark)", "scheme": "slate", "primary": "indigo", "accent": "indigo", |
| 90 | + "toggleIcon": "material/brightness-4", "toggleName": "Switch to light mode" } |
| 91 | + ] |
| 92 | + }, |
| 93 | +
|
| 94 | + // --- Navigation ------------------------------------------------------------------ |
| 95 | + // Omit `nav` to auto-generate from the docs folder structure. |
| 96 | + "nav": [ |
| 97 | + { "path": "index.md" }, |
| 98 | + { |
| 99 | + "title": "Getting started", |
| 100 | + "children": [ |
| 101 | + { "path": "getting-started/installation.md" }, |
| 102 | + { "path": "getting-started/quickstart.md" } |
| 103 | + ] |
| 104 | + } |
| 105 | + ], |
| 106 | +
|
| 107 | + // --- Markdown extensions --------------------------------------------------------- |
| 108 | + // Reference: {{DocsBase}}/reference/markdown-extensions/ |
| 109 | + "markdownExtensions": [ |
| 110 | + { "name": "admonition" }, |
| 111 | + { "name": "attr_list" }, |
| 112 | + { "name": "md_in_html" }, |
| 113 | + { "name": "footnotes" }, |
| 114 | + { "name": "toc", "options": { "permalink": true } }, |
| 115 | + { "name": "pymdownx.details" }, |
| 116 | + { "name": "pymdownx.superfences" }, |
| 117 | + { "name": "pymdownx.tabbed", "options": { "alternate_style": true } }, |
| 118 | + { "name": "pymdownx.highlight", "options": { "line_spans": "__span" } }, |
| 119 | + { "name": "pymdownx.tasklist", "options": { "custom_checkbox": true } }, |
| 120 | + { "name": "pymdownx.emoji" }, |
| 121 | + { "name": "pymdownx.keys" }, |
| 122 | + { "name": "pymdownx.critic" } |
| 123 | + ], |
| 124 | +
|
| 125 | + // --- Plugins --------------------------------------------------------------------- |
| 126 | + // Reference: {{DocsBase}}/plugins/ — remove any you don't need. |
| 127 | + "plugins": [ |
| 128 | + { "name": "search", "options": { "lang": "en" } }, |
| 129 | + { "name": "meta" }, |
| 130 | + { "name": "tags", "options": { "export": true } }, |
| 131 | + // { "name": "blog" }, // enable if you have a docs/blog/ folder |
| 132 | + // { "name": "rss", "options": { "atom": true, "social_icon": true } }, |
| 133 | + // { "name": "git-revision-date-localized" }, |
| 134 | + // { "name": "redirects" }, |
| 135 | + // { "name": "glightbox" }, |
| 136 | + // { "name": "macros" }, // fileuri()/button()/download() macros |
| 137 | + // { "name": "table-reader" }, // read_csv()/read_table() |
| 138 | + // { "name": "arithmatex" }, // LaTeX math |
| 139 | + // { "name": "social" } // OG cards; best behind `--prod` |
| 140 | + ], |
| 141 | +
|
| 142 | + // --- Extra: social links, custom vars -------------------------------------------- |
| 143 | + "extra": { |
| 144 | + "social": [ |
| 145 | + { "icon": "fontawesome/brands/github", "link": "https://github.com/you/my-project" } |
| 146 | + ] |
| 147 | + }, |
| 148 | +
|
| 149 | + // --- URL slugs ------------------------------------------------------------------- |
| 150 | + "slugify": { "case": "lower", "separator": "-", "ascii": false }, |
| 151 | +
|
| 152 | + // --- Output optimization --------------------------------------------------------- |
| 153 | + "optimize": { |
| 154 | + "minifyHtml": false, |
| 155 | + "minifyCss": false, |
| 156 | + "minifyJs": false, |
| 157 | + "convertImagesToWebp": false, |
| 158 | + "webpQuality": 80 |
| 159 | + }, |
| 160 | +
|
| 161 | + // --- Build-time validation ------------------------------------------------------- |
| 162 | + // Reference: {{DocsBase}}/reference/validation/ — pair with `netdocs build --strict`. |
| 163 | + "validation": { |
| 164 | + "links": false, // broken internal links |
| 165 | + "anchors": false, // broken #fragment anchors (requires links) |
| 166 | + "unusedImages": false, |
| 167 | + "orphanPages": false |
| 168 | + }, |
| 169 | +
|
| 170 | + // --- Deploy (optional) ----------------------------------------------------------- |
| 171 | + // target: "none" | "filesystem" | "git" | "s3" — run `netdocs deploy`. |
| 172 | + "deploy": { |
| 173 | + "target": "none" |
| 174 | + // "target": "git", "branch": "gh-pages", "remote": "origin" |
| 175 | + } |
| 176 | + } |
| 177 | +} |
| 178 | +
|
| 179 | +"""; |
| 180 | +} |
0 commit comments