# MANUAL — hanthebot.com landing page

This is the manual for the small Astro site served at <https://hanthebot.com>.
It replaces the old nginx redirect with a real page: one screen that explains
what the domain is for and a prominent link to <https://hanthebot.dev>.

The public portfolio is still `hanthebot.dev`. This domain is the lab — the VPS,
its private services and build previews. The page exists so that a person who
types `hanthebot.com` gets an explanation instead of an invisible bounce.

## 0. Current live setup (2026-11-27)

| Item | Value |
|---|---|
| nginx site file | `/etc/nginx/sites-available/www.hanthebot.com` |
| enabled as | `/etc/nginx/sites-enabled/www.hanthebot.com` |
| web root | `/home/hanthebot/chat/webpage/hanthebot-com/dist` |
| certificate | `~/.config/hosting/letsencrypt/config/live/hanthebot.com/{fullchain,privkey}.pem` |
| ACME webroot | `/home/hanthebot/chat/acme-sync` |
| renewal | existing `certbot-funmath.timer` runs `certbot renew` for the whole user certbot config and reloads nginx |
| config backup | `~/www.hanthebot.com.bak-2026-11-27-002745` |

The apex serves the build **directly from `dist/`**, so there is no copy or
rsync step. After `npm run build`, the live page is already updated. The nginx
worker needs read/execute access along `/home/hanthebot/chat/webpage/hanthebot-com/dist`;
the current directory permissions allow that.

`www.hanthebot.com` redirects to `https://hanthebot.com`, and HTTP redirects to
HTTPS on the apex. The certificate covers both names.

---

## 1. Why a page instead of a redirect

A `301` is efficient but dumb: it hides the identity of the `.com` name, leaves
search engines and link previews with nothing to show, and makes the two domains
look like a mistake. A one-screen static page is cheap, self-explanatory, and
still routes people to the public site in one click.

Design rules that follow from that:

- The primary call to action is always **Open hanthebot.dev**.
- No `<meta refresh>`, no JavaScript redirect. The page must answer the question
  first, then offer the link.
- Private services are described by role, never linked. `mgmt.`, `edit.`, shares
  and SSH stay gated.
- No external fonts, CDNs, analytics or trackers. The whole site is a handful of
  files and two tiny inline scripts (theme choice and the footer year).

---

## 2. What is in the project

```text
hanthebot-com/
├── astro.config.mjs                  # canonical origin: https://hanthebot.com
├── package.json                      # scripts: dev / build / build:preview / preview
├── src/
│   ├── config.ts                     # name, title, description, public links
│   ├── layouts/Base.astro            # head, nav, footer, theme toggle
│   ├── pages/index.astro             # the landing page (all copy lives here)
│   ├── pages/404.astro               # custom not-found page
│   └── styles/global.css             # every colour and layout rule
├── public/
│   ├── favicon.svg
│   └── robots.txt
├── scripts/make-relative.mjs         # preview-only path rewriting
├── deploy/
│   └── nginx-hanthebot.com.conf.example
└── MANUAL.md
```

Three kinds of facts, each with one home:

| Fact | Lives in |
|---|---|
| Page copy, service list, section order | `src/pages/index.astro` |
| Site name, title, description, public links | `src/config.ts` |
| Colours, spacing, typography | `src/styles/global.css` |
| Canonical domain | `astro.config.mjs` (and keep `SITE.url` in sync) |
| Server behaviour | nginx config on the VPS |

---

## 3. Local workflow

Requirements: Node.js 20 or newer (Astro 5). The tools already used by
`hanthebot-dev` are sufficient.

```bash
cd ~/chat/webpage/hanthebot-com
npm install          # once, or after changing package.json
```

| Command | What it does | Use it when |
|---|---|---|
| `npm run dev` | Dev server with live reload on `127.0.0.1:4321` | Editing copy or styles |
| `npm run build` | Production build in `dist/`, absolute URLs | Deploying |
| `npm run build:preview` | Build, then rewrite URLs relative | Previewing through the directory viewer |
| `npm run preview` | Serve the current `dist/` locally | Checking a production build |

If you work over SSH, forward the dev port:

```bash
ssh -L 4321:127.0.0.1:4321 <your-vps>
# then open http://localhost:4321 on your machine
```

Or build the preview variant and use the directory viewer:

```bash
npm run build:preview
```

```text
https://mgmt.hanthebot.com/s/webpage/hanthebot-com/dist/
```

`build:preview` exists only because the directory viewer serves the site from a
subdirectory. Deployment always uses plain `npm run build`.

---

## 4. Editing the page

### Copy and sections
Open `src/pages/index.astro`. The page is four sections: hero, the two-domain
comparison, "What runs here", and "Elsewhere". The service cards come from the
small `services` array at the top of the file. Keep the page short; it should
still make sense on a phone without scrolling far.

### Links, name, metadata
Open `src/config.ts`. `SITE.links.public` is the public site; the footer and all
CTAs use it. If the public domain ever changes, update it here **and** in
`astro.config.mjs` (`site`), then rebuild.

### Look and feel
Open `src/styles/global.css`. The two `html[data-theme='dark']` and
`html[data-theme='light']` blocks at the top define every colour. The rest of the
file is grouped by section with comments. The site mirrors `hanthebot.dev`:
dark by default, mono accents, no external fonts.

### 404
`src/pages/404.astro` is the only other route. It has the same primary link to
`hanthebot.dev`, so even a broken URL still routes people to the public site.

### Content style
- Proper grammar and capitalisation. No emojis.
- One sentence per card, no exclamation marks.
- Say "hanthebot.dev" when you mean the public site, "hanthebot.com" when you
  mean this box.
- Never link to `mgmt.`, `edit.`, share links, SSH or the VPN. Naming a gated
  service is fine; publishing a URL is not.

---

## 5. Deployment notes (reference)

The live cutover is already done; see §0. The steps below are the original
playbook and use a generic `/srv/www/hanthebot.com` root. **The live site does
not use that path** — nginx serves `dist/` directly, so a routine deploy is just
`npm run build`. Keep this section for rebuilding the server block or repeating
the setup on another domain.

### 5.1 Build locally

```bash
cd ~/chat/webpage/hanthebot-com
npm run build
ls dist/                # index.html, 404.html, _astro/, favicon.svg, robots.txt
```

### 5.2 Create the web root and copy the files

Pick one path and use it consistently. The examples use
`/srv/www/hanthebot.com`. If you prefer `/var/www/hanthebot.com`, substitute it
everywhere, including the nginx `root` line.

```bash
VPS=root@your-vps          # or an SSH alias such as hanthebot-vps
ssh "$VPS" 'install -d -m 755 /srv/www/hanthebot.com'
rsync -avz --delete dist/ "$VPS":/srv/www/hanthebot.com/
```

If you deploy as a non-root user, fix ownership once:

```bash
ssh "$VPS" 'sudo chown -R www-data:www-data /srv/www/hanthebot.com'
```

`www-data` is correct on Debian/Ubuntu. On a distro whose nginx user is `nginx`,
use that account instead. Keep files world-readable (`644`) and directories
`755`; nginx does not need write access.

### 5.3 Find the current apex server block

```bash
sudo nginx -T > /tmp/nginx-full.conf
grep -n -B4 -A30 'server_name .*hanthebot\.com' /tmp/nginx-full.conf
```

`nginx -T` prints the merged config with `# configuration file ...` headers, so
you can see the real file path. Common locations:

- `/etc/nginx/sites-available/hanthebot.com` (symlinked into `sites-enabled/`)
- `/etc/nginx/conf.d/hanthebot.com.conf`
- a block inside `/etc/nginx/nginx.conf`

Subdomains such as `mgmt.` and `edit.` have their own server blocks. Do not touch
them.

### 5.4 Replace the redirect

Back up first:

```bash
sudo cp /etc/nginx/sites-available/hanthebot.com \
        /etc/nginx/sites-available/hanthebot.com.bak-$(date +%F)
```

In the **apex** server block, remove the redirect and add the static root. Keep
every TLS line exactly as it is.

```nginx
server {
    listen 443 ssl http2;
    server_name hanthebot.com;

    # KEEP: ssl_certificate, ssl_certificate_key, options-ssl-nginx.conf, ...
    # KEEP: any Cloudflare / real-IP settings already present.

    # Remove this line:
    # return 301 https://hanthebot.dev$request_uri;

    # Add these:
    root /srv/www/hanthebot.com;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}
```

If the old redirect lives inside a `location` rather than directly in the server
block, remove that location instead. If there is already a `root` or `location /`
in the block, merge rather than duplicate them.

Then add the small extras:

```nginx
    error_page 404 /404.html;

    location = /404.html {
        internal;
    }

    location /_astro/ {
        try_files $uri =404;
        expires 1y;
    }

    add_header X-Content-Type-Options "nosniff" always;
    add_header Referrer-Policy "strict-origin-when-cross-origin" always;
    add_header X-Frame-Options "DENY" always;
    add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
```

The full target shape is in
[`deploy/nginx-hanthebot.com.conf.example`](deploy/nginx-hanthebot.com.conf.example).
Treat it as a reference, not a file to copy wholesale: your certificate paths,
listen directives and any Cloudflare configuration are already correct.

### 5.5 Make `www` point at the apex again

The old setup probably sent `www.hanthebot.com` to `hanthebot.dev` as well. Now
it should redirect to the apex of this domain:

```nginx
server {
    listen 443 ssl http2;
    server_name www.hanthebot.com;
    # keep TLS lines
    return 301 https://hanthebot.com$request_uri;
}
```

If the certificate does not cover `www`, either add it with certbot or leave the
existing `www` behaviour alone; it is not required for the landing page.

### 5.6 Validate and reload

```bash
sudo nginx -t
sudo systemctl reload nginx
```

Never reload if `nginx -t` fails. Fix the syntax or restore the backup.

### 5.7 Verify

```bash
# Apex should be 200 and must NOT contain a Location header.
curl -sSI https://hanthebot.com | sed -n '1,12p'

# The page should contain the main call to action.
curl -sS https://hanthebot.com | grep -F 'Open hanthebot.dev'

# www should redirect to the apex.
curl -sSI https://www.hanthebot.com | grep -i '^location'

# Subdomains should still behave as before.
curl -sSI https://mgmt.hanthebot.com | sed -n '1,3p'

# The custom 404 should be served.
curl -sSI https://hanthebot.com/definitely-not-a-real-path | sed -n '1,3p'
```

Expected: apex `200`, no `Location`; `www` `301` to `https://hanthebot.com/...`;
`mgmt.` unchanged; unknown apex paths `404`.

### 5.8 Cloudflare and cached redirects

If DNS for `hanthebot.com` is proxied through Cloudflare:

- Remove any **Redirect Rule** or **Page Rule** that sends `hanthebot.com/*` to
  `hanthebot.dev`. nginx is not the only place a redirect can live.
- Purge the cache for the apex after the cutover, or use "Purge Everything".
- Leave SSL/TLS mode on Full (strict); nothing about that changes.

Browsers also cache `301` responses aggressively. If your own browser still
redirects after the cutover, test with `curl` or a private window, and clear the
cached redirect for the site if necessary. This is not an nginx problem if
`curl` shows the page.

### 5.9 Certificate renewal

The live certificate is managed in the **user** certbot configuration, not
`/etc/letsencrypt`. Use the same directories as the deployed config:

```bash
certbot renew \
  --config-dir "$HOME/.config/hosting/letsencrypt/config" \
  --work-dir "$HOME/.config/hosting/letsencrypt/work" \
  --logs-dir "$HOME/.config/hosting/letsencrypt/logs" \
  --dry-run
```

The existing `certbot-funmath.timer` runs this renewal for the whole config dir
daily and reloads nginx with a deploy hook. The HTTP-01 challenge is served from
`/home/hanthebot/chat/acme-sync`; keep the `/.well-known/acme-challenge/`
location in the port-80 block. Do not replace it with a blanket server-level
`return`.

---

## 6. Routine updates

After editing copy or styles, rebuild in place:

```bash
cd ~/chat/webpage/hanthebot-com
npm run build
```

There is no copy step: nginx already points at `dist/`. Check the live page:

```bash
curl -sS https://hanthebot.com | grep -F 'Open hanthebot.dev' && echo ok
```

If Cloudflare is proxying the domain, purge the cache. You do not need to reload
nginx for content-only changes. Reload only when the nginx config itself changes:

```bash
sudo nginx -t && sudo systemctl reload nginx
```

---

## 7. Optional: atomic releases

**Not used by the current setup.** The live nginx root is `dist/`, so a rebuild
replaces the page immediately. The release-symlink pattern below is only useful
if you later move to a dedicated deploy root and want instant rollback.

```text
/srv/www/hanthebot.com/
├── releases/
│   ├── 2026-11-26T120000Z/
│   └── 2026-11-27T090000Z/
└── current -> releases/2026-11-27T090000Z
```

With `root /srv/www/hanthebot.com/current;`, deploy like this:

```bash
ts=$(date -u +%Y-%m-%dT%H%M%SZ)
ssh "$VPS" "install -d /srv/www/hanthebot.com/releases/$ts"
rsync -avz --delete dist/ "$VPS":/srv/www/hanthebot.com/releases/"$ts"/
ssh "$VPS" "ln -sfn /srv/www/hanthebot.com/releases/$ts /srv/www/hanthebot.com/current"
```

Rollback is then one symlink swap. If you prune old releases, check the path
before running any recursive delete:

```bash
ssh "$VPS" 'ls -1dt /srv/www/hanthebot.com/releases/* | tail -n +4'
```

---

## 8. Rollback

### Restore the previous nginx behaviour

The original file is backed up at
`/home/hanthebot/www.hanthebot.com.bak-2026-11-27-002745`:

```bash
cp /home/hanthebot/www.hanthebot.com.bak-2026-11-27-002745 \
   /etc/nginx/sites-available/www.hanthebot.com
sudo nginx -t && sudo systemctl reload nginx
```

If you only want the old redirect back, replace the apex server block with:

```nginx
return 301 https://hanthebot.dev$request_uri;
```

Reload nginx and verify with `curl -sSI https://hanthebot.com`.

### Restore the previous page

Rebuild from the last good commit:

```bash
git checkout -- src/    # or check out the last good commit
npm run build
```

No nginx reload is needed for a page rollback.

---

## 9. Troubleshooting

| Symptom | Likely cause | Fix |
|---|---|---|
| `https://hanthebot.com` still redirects to `.dev` | Browser-cached `301`, a Cloudflare redirect rule, or another nginx block matching first | Test with `curl -sSI`; inspect `nginx -T`; purge Cloudflare; clear the browser redirect cache |
| Apex returns `404` | `root` path wrong, `index.html` missing, or `try_files` still pointing elsewhere | Check `ls ~/chat/webpage/hanthebot-com/dist`; confirm `root` and `index` in the apex block |
| Page loads but CSS is missing | `_astro/` was not built, or the wrong `root` is being served | `ls ~/chat/webpage/hanthebot-com/dist/_astro/`; run `npm run build`; check the browser network tab |
| `403 Forbidden` | File permissions or the nginx user cannot traverse the path | `namei -l ~/chat/webpage/hanthebot-com/dist/index.html`; every directory needs world execute, files world read |
| HTTPS shows `funmath.hanthebot.com` or the wrong certificate | `ssl_certificate` points at the wrong lineage, or nginx was not reloaded | `echo | openssl s_client -connect hanthebot.com:443 -servername hanthebot.com 2>/dev/null | openssl x509 -noout -subject -ext subjectAltName`; point to `~/.config/hosting/letsencrypt/config/live/hanthebot.com/`; reload |
| `nginx -t` fails | Missing semicolon, unbalanced brace, or a TLS path that no longer exists | Restore the backup, then re-apply the edit in smaller steps |
| `www` redirects to `.dev` | The `www` block was not updated | Change its `return` target to `https://hanthebot.com$request_uri` |
| `https://hanthebot.com/foo` returns `404` | Expected: only `/` and static assets exist | That is the normal behaviour; keep the custom 404 |
| Certificate renewal fails | ACME challenge location was removed or the webroot changed | Keep `location /.well-known/acme-challenge/ { root /home/hanthebot/chat/acme-sync; }`; run `certbot renew --dry-run` with the user config dirs |
| Subdomain broke | The apex edit touched a shared or wildcard block | Restore the backup; keep `mgmt.`/`edit.` in their own server blocks |
| Theme flash on load | The pre-paint script was removed from `Base.astro` | Keep the inline `localStorage` script in `<head>` |

Useful commands:

```bash
sudo nginx -T | less
sudo tail -n 50 /var/log/nginx/error.log
sudo tail -n 50 /var/log/nginx/access.log
namei -l ~/chat/webpage/hanthebot-com/dist/index.html
```

---

## 10. Before going live — checklist

- [ ] `npm run build` passes and `dist/` contains `index.html`, `404.html`, `_astro/`
- [ ] The page reads correctly at ~390 px and at desktop width
- [ ] Every CTA points at `https://hanthebot.dev`
- [ ] No gated service is linked (`mgmt.`, `edit.`, shares, SSH, VPN)
- [ ] `http://` redirects to `https://`, and `www` redirects to the apex
- [ ] `/` returns `200`; an unknown path returns the custom `404`
- [ ] `sudo nginx -t` passes and the config is backed up
- [ ] Cloudflare redirect rules removed and cache purged (if proxied)
- [ ] `sudo certbot renew --dry-run` passes (user certbot config; see §5.9)
- [ ] `mgmt.` and other subdomains still respond as before

---

## 11. One home per fact

When something changes, change it in exactly one place:

- Public destination URL → `src/config.ts`, then rebuild.
- Canonical domain → `astro.config.mjs` and `SITE.url`, then rebuild.
- Copy → `src/pages/index.astro`.
- Colours → top of `src/styles/global.css`.
- Server root, TLS, redirects → nginx config on the VPS.

If you find yourself editing the generated `dist/` files, stop: the next build
will overwrite them.
