diff --git a/website/README.md b/website/README.md index 12fffe8..43ed6b5 100644 --- a/website/README.md +++ b/website/README.md @@ -35,9 +35,9 @@ Static assets, like favicons, can be placed in the `public/` directory. All commands are run from the root of the project, from a terminal: -| Command | Action | -| :------------------------ | :----------------------------------------------- | -| `bun install` | Installs dependencies | +| Command | Action | +| :-------------------- | :----------------------------------------------- | +| `bun install` | Installs dependencies | | `bun dev` | Starts local dev server at `localhost:4321` | | `bun build` | Build your production site to `./dist/` | | `bun preview` | Preview your build locally, before deploying | diff --git a/website/astro.config.mjs b/website/astro.config.mjs index 34056c5..ed14870 100644 --- a/website/astro.config.mjs +++ b/website/astro.config.mjs @@ -4,36 +4,36 @@ import starlight from "@astrojs/starlight"; // https://astro.build/config export default defineConfig({ - integrations: [ - starlight({ - title: "tg", - social: [ - { - icon: "github", - label: "Tangled", - href: "https://tangled.org/aly.codes/tg", - }, - ], - components: { - // Override SocialIcons to render the Tangled Dolly mark for the - // tangled.org link instead of a generic icon. - SocialIcons: "./src/components/SocialIcons.astro", - // Override Head to avoid "tg | tg" on the homepage (page title == site title). - Head: "./src/components/Head.astro", - // Override Footer to link to aly.codes instead of Starlight credits. - Footer: "./src/components/Footer.astro", - }, - sidebar: [ - { - label: "Cookbooks", - items: [{ autogenerate: { directory: "cookbooks" } }], - }, - { - label: "Reference", - // Generated at build time from `tg man --markdown` (see scripts/gen-commands.mjs). - items: [{ autogenerate: { directory: "reference/commands" } }], - }, - ], - }), - ], + integrations: [ + starlight({ + title: "tg", + social: [ + { + icon: "github", + label: "Tangled", + href: "https://tangled.org/aly.codes/tg", + }, + ], + components: { + // Override SocialIcons to render the Tangled Dolly mark for the + // tangled.org link instead of a generic icon. + SocialIcons: "./src/components/SocialIcons.astro", + // Override Head to avoid "tg | tg" on the homepage (page title == site title). + Head: "./src/components/Head.astro", + // Override Footer to link to aly.codes instead of Starlight credits. + Footer: "./src/components/Footer.astro", + }, + sidebar: [ + { + label: "Cookbooks", + items: [{ autogenerate: { directory: "cookbooks" } }], + }, + { + label: "Reference", + // Generated at build time from `tg man --markdown` (see scripts/gen-commands.mjs). + items: [{ autogenerate: { directory: "reference/commands" } }], + }, + ], + }), + ], }); diff --git a/website/package.json b/website/package.json index 570d079..84e0537 100644 --- a/website/package.json +++ b/website/package.json @@ -2,17 +2,17 @@ "name": "", "type": "module", "version": "0.0.1", - "scripts": { - "gen:commands": "node scripts/gen-commands.mjs", - "dev": "node scripts/gen-commands.mjs && astro dev", - "start": "node scripts/gen-commands.mjs && astro dev", - "build": "node scripts/gen-commands.mjs && astro build", - "preview": "astro preview", - "astro": "astro" - }, + "scripts": { + "gen:commands": "node scripts/gen-commands.mjs", + "dev": "node scripts/gen-commands.mjs && astro dev", + "start": "node scripts/gen-commands.mjs && astro dev", + "build": "node scripts/gen-commands.mjs && astro build", + "preview": "astro preview", + "astro": "astro" + }, "dependencies": { "@astrojs/starlight": "^0.41.5", "astro": "^7.0.2", "sharp": "^0.34.5" } -} \ No newline at end of file +} diff --git a/website/scripts/gen-commands.mjs b/website/scripts/gen-commands.mjs index ede5d6e..0778247 100644 --- a/website/scripts/gen-commands.mjs +++ b/website/scripts/gen-commands.mjs @@ -1,47 +1,47 @@ -import { spawnSync } from 'node:child_process'; +import { spawnSync } from "node:child_process"; import { - existsSync, - mkdirSync, - mkdtempSync, - readdirSync, - readFileSync, - rmSync, - writeFileSync, -} from 'node:fs'; -import { basename, dirname, extname, join, resolve } from 'node:path'; -import { fileURLToPath } from 'node:url'; -import { tmpdir } from 'node:os'; + existsSync, + mkdirSync, + mkdtempSync, + readdirSync, + readFileSync, + rmSync, + writeFileSync, +} from "node:fs"; +import { basename, dirname, extname, join, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; +import { tmpdir } from "node:os"; // Resolve paths relative to this script so it works regardless of CWD. -const siteRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..'); -const repoRoot = resolve(siteRoot, '..'); -const outDir = join(siteRoot, 'src/content/docs/reference/commands'); +const siteRoot = resolve(dirname(fileURLToPath(import.meta.url)), ".."); +const repoRoot = resolve(siteRoot, ".."); +const outDir = join(siteRoot, "src/content/docs/reference/commands"); // Prefer the repo-root build output (`go build -o tg ./cmd/tg`), else PATH. -const localBin = join(repoRoot, 'tg'); -const tg = existsSync(localBin) ? localBin : 'tg'; +const localBin = join(repoRoot, "tg"); +const tg = existsSync(localBin) ? localBin : "tg"; function run(args) { - return spawnSync(tg, args, { encoding: 'utf8' }); + return spawnSync(tg, args, { encoding: "utf8" }); } -const canary = run(['--help']); +const canary = run(["--help"]); if (canary.error || canary.status !== 0) { - console.error( - `gen-commands: could not run ${tg} — build it first with \`go build -o tg ./cmd/tg\` from the repo root, or install tg on your PATH.`, - ); - if (canary.stderr) console.error(canary.stderr.trim()); - process.exit(1); + console.error( + `gen-commands: could not run ${tg} — build it first with \`go build -o tg ./cmd/tg\` from the repo root, or install tg on your PATH.`, + ); + if (canary.stderr) console.error(canary.stderr.trim()); + process.exit(1); } // Stage raw Cobra markdown in a temp dir, then transform into Starlight content. -const stage = mkdtempSync(join(tmpdir(), 'tg-commands-')); -const gen = run(['man', stage, '--markdown']); +const stage = mkdtempSync(join(tmpdir(), "tg-commands-")); +const gen = run(["man", stage, "--markdown"]); if (gen.error || gen.status !== 0) { - console.error('gen-commands: `tg man --markdown` failed:'); - if (gen.stderr) console.error(gen.stderr.trim()); - rmSync(stage, { recursive: true, force: true }); - process.exit(1); + console.error("gen-commands: `tg man --markdown` failed:"); + if (gen.stderr) console.error(gen.stderr.trim()); + rmSync(stage, { recursive: true, force: true }); + process.exit(1); } rmSync(outDir, { recursive: true, force: true }); @@ -53,49 +53,49 @@ const seeAlsoRe = /\((tg[\w-]*)\.md\)/g; const autoTagRe = /^###### Auto generated by spf13\/cobra.*$\n?/m; function yaml(s) { - return `"${String(s).replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`; + return `"${String(s).replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`; } let count = 0; for (const file of readdirSync(stage)) { - if (extname(file) !== '.md') continue; - let body = readFileSync(join(stage, file), 'utf8').replace(autoTagRe, ''); - let title = basename(file, '.md').replace(/_/g, ' '); - let description = ''; + if (extname(file) !== ".md") continue; + let body = readFileSync(join(stage, file), "utf8").replace(autoTagRe, ""); + let title = basename(file, ".md").replace(/_/g, " "); + let description = ""; - // Pull the title + short description from Cobra's leading "## \n\n". - const lines = body.split('\n'); - let i = 0; - while (i < lines.length && !lines[i].startsWith('## ')) i++; - if (i < lines.length) { - title = lines[i].slice(3).trim(); - i++; // drop the heading; the frontmatter title renders as H1 - while (i < lines.length && lines[i].trim() === '') i++; - if (i < lines.length && !lines[i].startsWith('#')) { - description = lines[i].trim(); - body = lines.slice(i).join('\n'); - } else { - body = lines.slice(i).join('\n'); - } - } + // Pull the title + short description from Cobra's leading "## \n\n". + const lines = body.split("\n"); + let i = 0; + while (i < lines.length && !lines[i].startsWith("## ")) i++; + if (i < lines.length) { + title = lines[i].slice(3).trim(); + i++; // drop the heading; the frontmatter title renders as H1 + while (i < lines.length && lines[i].trim() === "") i++; + if (i < lines.length && !lines[i].startsWith("#")) { + description = lines[i].trim(); + body = lines.slice(i).join("\n"); + } else { + body = lines.slice(i).join("\n"); + } + } - body = body.replace(seeAlsoRe, '(/reference/commands/$1/)'); + body = body.replace(seeAlsoRe, "(/reference/commands/$1/)"); - const frontmatter = [ - '---', - `title: ${yaml(title)}`, - description ? `description: ${yaml(description)}` : null, - '---', - '', - ] - .filter(Boolean) - .join('\n'); + const frontmatter = [ + "---", + `title: ${yaml(title)}`, + description ? `description: ${yaml(description)}` : null, + "---", + "", + ] + .filter(Boolean) + .join("\n"); - writeFileSync(join(outDir, file), `${frontmatter}\n${body}`); - count++; + writeFileSync(join(outDir, file), `${frontmatter}\n${body}`); + count++; } rmSync(stage, { recursive: true, force: true }); console.log( - `gen-commands: wrote ${count} command pages to src/content/docs/reference/commands/`, + `gen-commands: wrote ${count} command pages to src/content/docs/reference/commands/`, ); diff --git a/website/src/content.config.ts b/website/src/content.config.ts index d9ee8c9..7fbcf2c 100644 --- a/website/src/content.config.ts +++ b/website/src/content.config.ts @@ -1,7 +1,7 @@ -import { defineCollection } from 'astro:content'; -import { docsLoader } from '@astrojs/starlight/loaders'; -import { docsSchema } from '@astrojs/starlight/schema'; +import { defineCollection } from "astro:content"; +import { docsLoader } from "@astrojs/starlight/loaders"; +import { docsSchema } from "@astrojs/starlight/schema"; export const collections = { - docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }), + docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }), }; diff --git a/website/src/content/docs/index.mdx b/website/src/content/docs/index.mdx index e01f1ae..fda5a69 100644 --- a/website/src/content/docs/index.mdx +++ b/website/src/content/docs/index.mdx @@ -14,21 +14,17 @@ hero: variant: minimal --- -import { Card, CardGrid, LinkCard } from '@astrojs/starlight/components'; +import { Card, CardGrid, LinkCard } from "@astrojs/starlight/components"; ## Install - - ```bash - nix profile add github:alyraffauf/tg - ``` - - - ```bash - go install github.com/alyraffauf/tg/cmd/tg@latest - ``` - + + ```bash nix profile add github:alyraffauf/tg ``` + + + ```bash go install github.com/alyraffauf/tg/cmd/tg@latest ``` + ## Quick start @@ -41,6 +37,14 @@ tg repo clone aly.codes/tg ## Guides - - + +