# GUIDE — editing and running hanthebot.dev

This is the manual for the production portfolio site. It is a small Astro build:
content lives in markdown, the renderer turns it into plain HTML, and nothing
external is requested at runtime (no fonts, no trackers, no CDNs).

---

## 1. The one-minute mental model

```
you edit markdown / config  →  npm run build  →  dist/  →  view through the dir viewer
```

Three kinds of "content" exist, and each has exactly one home:

| Content | Lives in | Appears as |
|---|---|---|
| Projects | `src/content/projects/*.md` | Cards on grids + one page each |
| Log entries (blog posts) | `src/content/logs/*.md` | Lists, tag pages, RSS, one page each |
| Site-level facts (name, links, hero text) | `src/config.ts` | Everywhere |

Pages in `src/pages/` only *render* collections — you rarely need to touch them.
A build-time check (Zod, defined in `src/content.config.ts`) validates every
frontmatter field; a typo fails the build with the exact file and field named.

---

## 2. Render (all the commands that matter)

```bash
cd ~/chat/webpage/hanthebot-dev
npm run install           # once
npm run build             # production build, relative paths → dist/
npm run build:drafts      # same, but draft posts included (preview)
npm run dev               # live-reload server on 127.0.0.1:4321 (SSH tunnel)

npm run post "Title" --tags meta --draft    # scaffold a log entry
npm run project "Title" --type hardware     # scaffold a project
npm run github                              # print a GitHub repo reference table
```

View the built site through the directory viewer (never open `src/`, never use
`file://`):

- Home: `https://mgmt.hanthebot.com/s/webpage/hanthebot-dev/dist/`
- Projects: `…/dist/projects/`
- Demo (NTT): `…/dist/projects/fft-ntt/`
- Lab (receipt): `…/dist/lab/receipt-guestbook/`

Directory URLs open their `index.html` automatically. This works because the
share daemon was updated for the same behavior. For any other folder on any
share, append `?list=1` to a directory URL to view it as a file listing.

`dist/` is intentionally portable: `npm run build` rewrites every internal link
to a path-relative one, so the folder can be served from *any* mount point
(subdirectory viewer today, domain root tomorrow) with zero rebuild.
For a Cloudflare Pages deploy you would normally skip that step:

```bash
npm run build:deploy      # absolute URLs, pretty for a real domain root
```

Which path is live where is a decision to make at deploy time; nothing else
changes between the two modes.

---

## 3. Directory map

```
hanthebot-dev/
├── astro.config.mjs        # Astro settings (site, sitemap, code themes)
├── src/
│   ├── config.ts           # names, links, hero text, label vocabularies
│   ├── content.config.ts   # frontmatter schema for projects + logs (validation)
│   ├── content/
│   │   ├── projects/*.md   # one file per project
│   │   └── logs/*.md       # one file per log entry (blog post)
│   ├── layouts/Base.astro  # <html> shell: head, header, footer, skip link
│   ├── components/         # Header, Footer, ProjectCard, LogRow, ProjectFilter…
│   ├── pages/              # URL structure lives here (see below)
│   ├── scripts/            # vanilla-JS islands (ntt.js, receipt.js)
│   └── styles/global.css   # the whole look; colors at the top
├── scripts/                # tooling: make-relative, new-post, new-project, github
├── public/                 # copied verbatim: favicon.svg, robots.txt
└── dist/                   # build output — this is what gets viewed
```

`src/pages/` is one folder = one URL prefix:

```
pages/index.astro                 → /
pages/projects/index.astro        → /projects/
pages/projects/[slug].astro       → /projects/<any-project>/      (auto from content)
pages/projects/type/[type].astro  → /projects/type/<research|…>/
pages/logs/index.astro            → /logs/
pages/logs/[slug].astro           → /logs/<any-log-entry>/       (auto from content)
pages/logs/tag/[tag].astro        → /logs/tag/<tag>/
pages/lab/receipt-guestbook.astro → /lab/receipt-guestbook/
pages/rss.xml.ts                  → /rss.xml
pages/404.astro                   → /404.html
```

---

## 4. Recipes

### 4.1 Change site-level facts (name, links, hero, status text)
Open `src/config.ts`. Every value is a plain string with a comment. Set a link
to `''` to hide it everywhere (hero, footer, about). Rebuild.

### 4.2 Add or edit a project
Easiest: `npm run project "Title" --type systems` — a pre-filled file appears in
`src/content/projects/`. Then edit the frontmatter:

```yaml
title: My Project
tagline: One sentence shown on the card.
type: research        # research | systems | hardware | hobby
status: active        # active | hibernating | archived
authorship: own       # own | ai-assisted | vibe-coded | own-hw-vibe-fw (or omit)
featured: true        # puts the card on the homepage selection
order: 15             # sort position on grids (lower first)
stack: ['Python']     # small chips under the tagline
links:                # all optional; omit the whole block for none
  repo: https://github.com/Hanthebot/…
  live: https://…
  demo: /lab/…        # path on this site or full URL
  writeup: /logs/…
demoIsland: ntt       # optional; mounts a built-in demo (see §6)
note: Private infrastructure — write-up pending   # optional line under the links
```

Below the frontmatter, 1–3 paragraphs of markdown = the project page body.
Delete the scaffold instructions when done. Card counts, type pages and the
homepage selection all update automatically on rebuild.

The `authorship` vocabulary is deliberately tiny and lives in `src/config.ts`
(`AUTHORSHIP_LABELS`): the point is that a reader can trust the labels because
there are exactly four of them and nothing else.

### 4.3 Write a log entry (and the draft workflow)
`npm run post "Measuring X" --tags crypto,bench` creates
`src/content/logs/2026-10-31-measuring-x.md` marked as a draft:

- `npm run build` — drafts are **excluded** from lists, pages, RSS and the tag pages.
- `npm run build:drafts` — drafts appear, marked with a "Draft" pill (preview only).
- `npm run dev` — drafts always visible while writing.
- To publish: flip `draft: true` to `false` (or delete the line) and `npm run build`.

Frontmatter is `title`, `description` (one line for lists/previews), `pubDate`,
`tags`, `draft`. The body renders full markdown with syntax-highlighted code
blocks, tables, and images.

### 4.4 Change how the site looks
All colors live in the two `html[data-theme=…]` blocks at the top of
`src/styles/global.css` (dark is the default). Typography, spacing, cards and
the receipt styling follow in the same file, commented per section.

### 4.5 Add a page
Create `src/pages/whatever.astro`, wrap content in
`<Base title="…" description="…">…</Base>`, add the relative import path (count
the folder depth) and, optionally, a nav entry in `src/components/Header.astro`.
To render a markdown file behind it, prefer a content collection entry over a
hardcoded page (§4.2 / §4.3).

### 4.6 Add a component
Drop `src/components/MyThing.astro`, import it in a page or layout, and pass
props through a normal `interface Props`. Components are server-rendered plain
HTML — no hydration, no runtime — so they are cheap and safe to compose.

### 4.7 Add an island (interactive browser logic)
Islands are vanilla JS in `src/scripts/`, bundled per page, no framework:

1. Write `src/scripts/my-demo.js` exporting `mountMyDemo()`. Two rules:
   guard on your root element (`if (!document.getElementById('x')) return;`) so
   the mount can be called on pages that lack the markup, and never fetch
   anything at page load.
2. In the relevant page, render the DOM at a feature flag (see the
   `demoIsland === 'ntt'` block in `src/pages/projects/[slug].astro`).
3. If it should mount automatically, add the call in `src/scripts/islands.js`
   (both existing islands live behind `mountNTT()` / `mountReceipt()`).

Island intensity ladder (from SITE_STRUCTURE.md — keep honoring it): SVG/canvas
visualization → precomputed static JSON numbers → optional click-to-load compute
→ real backend only on the lab domain when truly needed.

---

## 5. Validation & troubleshooting

- **Build fails with "Invalid … / Expected …"** → a frontmatter field broke the
  schema in `src/content.config.ts`. The error names the file and field. Fix the
  md file, not the page.
- **Import path errors like "Could not resolve ../../…"** → Astro files import
  by literal path; count the directory depth (`pages/xxx/yyy.astro` needs three
  `../` to reach `src/layouts/`).
- **Styles not applied on a nested page** → you edited the view before
  `make-relative.mjs` ran, or you opened `dist/` after `build:deploy` (absolute
  paths) through the subdir viewer. Run `npm run build` (relative) and view again.
- **The NTT demo changed and looks wrong** → it self-verifies; run
  `node src/scripts/ntt.js`-style check via `node -e` on the exported functions,
  or just read the ✓/✗ lines in the demo readout on the page.
- **Drafts missing from a build** → that is the production behavior. Use
  `build:drafts` or `dev` to see them.

---

## 6. Style rules for content (keep these)

- Proper grammar and capitalization everywhere. No emojis, no kaomoji.
- Taglines: one sentence, no exclamation marks.
- Status uses only the fixed values; authorship uses only the four labels.
- The default demo (n = 8, Fibonacci coefficients) is the "always correct"
  state; do not ship a demo that fails its own self-check.
- One home per fact: a project's links live in its frontmatter, the site's
  socials live in `src/config.ts`, page copy lives in `src/pages/`.

---

## 7. Deploying (when/if)

The build is already deploy-ready: `npm run build:deploy` → push `dist/` to any
static host (Cloudflare Pages: build `npm run build:deploy`, output `dist`).
Metadata (canonical URLs, sitemap, RSS) points at hanthebot.dev; if the site
lands somewhere else instead, update `site` in `astro.config.mjs` and
`SITE.url` in `src/config.ts`, rebuild once.
