seo: per-route HTML + genuine 404, security headers, heading hierarchy (spec-v8)

Stage 1 (audit 4.1/4.2/4.4): scripts/generate-route-pages.ts (pnpm generate:routes, chained into build before the sitemap) rewrites the built head per route — title/description/canonical/og/twitter from the new ui/meta group (the six static manifests claim it) or from the project records — adds manifest-claimed <noscript> bodies and writes dist/404.html; nginx.conf resolves each URL against its generated file (try_files $uri/index.html $uri =404 + server-level error_page) so known routes answer 200 at the exact URL and unknown URLs a real 404; App.tsx adds the lazy catch-all route + src/pages/NotFoundPage.tsx for dead links inside the SPA (ui/common notFound keys, EN+VI); generate-sitemap.ts derives lastmod from the git history of the documents backing each URL and fails the build when a sitemap URL has no generated route file.

Stage 2 (audit 4.3/4.6): nginx.conf only — CSP (Report-Only, script-src carries the theme-init inline script hash, verified against the built bytes by the route generator), HSTS, nosniff, Referrer-Policy, Permissions-Policy, X-Frame-Options at server level and repeated in the two blocks that declare their own add_header; gzip_types for CSS/JS/JSON/SVG/XML with the hashed-asset immutable caching preserved.

Stage 3 (audit 4.7): SectionHeading gains level='h1'|'h2' and the six standalone pages render their top heading as h1; project detail blocks move h3->h2 and section titles h4->h3; diagram/code sections render in <pre class=project-diagram>, the Markdown fences are stripped from the two VI ASCII diagrams, the internal section-type chip renders only in edit mode; og:image declares the real 500x667.

docs: the 2026-10-29 site audit and spec-v8-seo-hardening (stages 1-3 repo-side DONE; owner browser walkthrough, CSP enforcement decision D5 and stage 4 D4 open).
This commit is contained in:
dong.nguyen committed 2026-11-02 13:02:53 +07:00
1 parent e02fe19bbe
commit 0dd2c6b3ee
32 files changed
+1181 -47

No files matched your search

+7 -3
View File
@@ -23,7 +23,7 @@ Personal engineering portfolio — multi-page SPA built with React + TypeScript
| Command | Description |
|---------|-------------|
| `pnpm dev` | Start dev server with HMR |
| `pnpm build` | Type-check (`tsc -b`), build for production (the site-identity plugin fills `%SITE_URL%` / `%SITE_NAME%` in `index.html`), then generate `dist/sitemap.xml` + `dist/robots.txt` |
|`pnpm build`|Type-check (`tsc -b`), build for production (the site-identity plugin fills `%SITE_URL%` / `%SITE_NAME%` in `index.html`), then generate the per-route pages (`dist/<route>/index.html` + `dist/404.html`), then `dist/sitemap.xml` + `dist/robots.txt`|
| `pnpm build:resume` | Generate resume PDF (default EN) via Playwright |
| `pnpm build:resume-all` | Generate bilingual resume PDFs (EN + VI) |
| `pnpm lint` | Run Oxlint |
@@ -53,6 +53,7 @@ Personal engineering portfolio — multi-page SPA built with React + TypeScript
| `/contact` | `ContactPage` | Contact info |
| `/philosophy` | `PhilosophyPage` | Engineering philosophy |
| `/how-it-works` | `HowItWorksPage` | Intro video: git-backed content, live editing, CI deploy |
| `*` (catch-all) | `NotFoundPage` | In-app 404 for dead links inside the SPA; direct hits on unknown URLs are answered by nginx with a real 404 + the generated `404.html` |
## Theming
@@ -77,7 +78,7 @@ Content is split once, at authoring time, into language-neutral **structure docu
- `src/data/skills.json` + `skills.ts` loader — skill groups: `{id, skills}`; group titles are text
- `src/data/experience.json` + `experience.ts` loader — work history: id / location / logo / optional `variant: 'current' | 'gap'` (timeline decoration: live node / career break); company, duration, titles and responsibilities are text — the VI document carries localized dates ("11/2026 – nay") and company labels, en overrides with the originals, proper nouns identical per language
- `src/data/projects.json` + `projects.ts` loader — cards: category / technologies / featured / `sections[].{id, type}`; titles, summaries, role, metrics and section prose are text (role follows the owner's EN title convention; metrics are localized)
- `src/i18n/locales/{vi,en}/content/{profile,skills,experience,projects}.json` — all content text, one file per entity, keyed by the structure ids; the `profile` record is fixed-keyed (`name`, `title`, `bio`, `subtitle`, `tldr`, `tagline`, `currentInterests`, `roles`, `philosophyQuotes`, `philosophy.<id>.{title, description, keywords}`); `src/i18n/locales/{vi,en}/ui/{group}.json` — 15 chrome groups (`navigation`, `footer`, `social`, `hero`, `about`, `expertise`, `experience`, `projects`, `projectDetail`, `contact`, `philosophy`, `howItWorks`, `resume`, `edit`, `common`), in each language (nav group labels, Mode options, language names `langEn` / `langVi`, action labels, social `aria-label`s, the resume's section labels, edit-mode labels) — person text never lives here; `src/i18n/index.ts` merges both trees back into the same `UI`/`CONTENT` records and asserts the merge against the group lists — a group dropped in the split is a load-time error, never a silent omission
- `src/i18n/locales/{vi,en}/content/{profile,skills,experience,projects}.json` — all content text, one file per entity, keyed by the structure ids; the `profile` record is fixed-keyed (`name`, `title`, `bio`, `subtitle`, `tldr`, `tagline`, `currentInterests`, `roles`, `philosophyQuotes`, `philosophy.<id>.{title, description, keywords}`); `src/i18n/locales/{vi,en}/ui/{group}.json` — 16 chrome groups (`navigation`, `footer`, `social`, `hero`, `about`, `expertise`, `experience`, `projects`, `projectDetail`, `contact`, `philosophy`, `howItWorks`, `resume`, `edit`, `common`, `meta`), in each language (nav group labels, Mode options, language names `langEn` / `langVi`, action labels, social `aria-label`s, the resume's section labels, edit-mode labels, the `notFound` 404 texts, and `meta` — the per-page SEO title/description the route generator writes into each page's head, keyed by PageId for the six static pages and claimed by exactly those six manifests; project pages derive their meta from the content records instead) — person text never lives here; `src/i18n/index.ts` merges both trees back into the same `UI`/`CONTENT` records and asserts the merge against the group lists — a group dropped in the split is a load-time error, never a silent omission
- Content ids and the category values a project uses are **generated**, never hand-maintained (spec: `docs/design/specs/v5/spec-v5-generated-content-ids.md`): `scripts/generate-content-types.ts` reads the four structure documents and writes `src/types/content-ids.ts` (gitignored) under `predev` / `prebuild` / `prepare`; `src/types/index.ts` re-exports those unions type-only and keeps only the code-owned ones (`Language`, `Palette`, `SocialId`, `PageId`, manifest types). A content add or delete touches JSON only — a text entry left behind by a deleted record is a `tsc` error (`TS2741`), never a stale union member — and a category with no label in either language is a validator error naming both `ui/projects.json` files (rule 7)
- `src/data/pages/{home,about,experience,projects,project-detail,contact,philosophy,how-it-works,resume}.json` + `pages.ts` loader — per-route manifests: which entity fields the page renders (`fields[]`; `*` = every field the record id owns) and which UI groups it reads; `src/types/index.ts` carries `PageId` / `PageManifestClaim` / `PageManifest`. A manifest describes the whole page, chrome included — the footer renders `profile.name` on every route, so every manifest claims it. The validator enforces: no unknown entity, no unknown UI group, no unresolvable field path, **no orphan text field** (every text leaf in the content documents is claimed by at least one manifest), no missing manifest for a route in `src/data/navigation.ts` plus `/projects/:id`
- `src/i18n/index.ts` — load + validate + join ONCE at module load; exports `UI` and `CONTENT` as `Record<Language, Resolved…>`; `src/i18n/dict-types.ts` carries the document types; `src/i18n/validate.ts` + `scripts/validate-content.ts` enforce the cross-document rules (orphan or missing keys, HTML markup in text values, the manifest rules above) — a malformed document fails `pnpm build`, CI, and the browser load, never a silent half-render
@@ -142,12 +143,13 @@ video/ # standalone Remotion project (spec-v7-intro-video), a pnpm work
- `public/resume-logos/` — official company logo SVGs (Lazada, SAP from Wikimedia Commons), embedded in the resume timeline via `ExperienceEntry.logo`
- `public/resume-qr/` — owner-supplied QR images (`telegram.jpg`, `zalo.jpg`) embedded in the resume header via `resumeQr` in `src/data/resume.ts`; committed like the other resume assets, so CI renders the QR block too — a missing file prints a warning and that QR is skipped
- `public/profile-photo.webp` — profile photo
- `robots.txt` is generated, not committed: `scripts/generate-sitemap.ts` writes `dist/robots.txt` (allow-all + the `Sitemap:` pointer) from the same `SITE_URL` the sitemap uses — no `public/robots.txt` exists anymore
- `robots.txt` is generated, not committed: `scripts/generate-sitemap.ts` writes `dist/robots.txt` (allow-all + the `Sitemap:` pointer) from the same `SITE_URL` the sitemap uses — no `public/robots.txt` exists anymore; the sitemap's `lastmod` per URL is the newest git commit touching the documents that back that page (manifest, claimed entity documents, claimed UI groups), falling back to the build date only when git is unavailable, and a guard refuses any sitemap URL whose generated route file is missing
## Scripts
- `scripts/generate-resume.ts` — Playwright-based PDF resume generator (bilingual en/vi)
- `scripts/generate-content-types.ts` — writes `src/types/content-ids.ts` from the four structure documents (`pnpm generate:ids`, wired as `predev` / `prebuild` / `prepare`): the id unions and the project category values in document order, `never` for an emptied document, a duplicate id refused with the file named
- `scripts/generate-route-pages.ts` — the route-page generator (`pnpm generate:routes`, run by `build` after `vite build`, before the sitemap step; spec-v8 §2): rewrites `dist/index.html`'s head per route with page-specific title/description/canonical/og (static pages from the `meta` UI group, project pages from their content records), adds a manifest-claimed `<noscript>` body to every page, writes `dist/404.html` (client-free links + `<meta http-equiv="refresh">` to `/`), and fails the build when an inline script's SHA-256 no longer matches the CSP hash in `nginx.conf`
- `scripts/smoke-draft.ts` — regression check of the draft-store semantics (`pnpm tsx scripts/smoke-draft.ts`): accept/reject paths, empty-required rejection, orphan-free record delete, template creation, id re-sluging on rename, snapshot round-trip, conflict detection, clean rebase, the category-label rule, the scoped-baseline rules of spec-v4-live-edit §5.1 (an adopted baseline replaces an untouched document only; a bundle-seeded document is never PUT over the branch), and the 409 path of spec-v6 D5 (a conflict refreshes the base, keeps the draft, and never stops the sequence)
- `scripts/smoke-generated-ids.ts` — regression check of the generator (`pnpm tsx scripts/smoke-generated-ids.ts`): the shipped module equals the shipped documents, byte-stable output, `never` for emptied documents, malformed documents refused with the file named
@@ -158,6 +160,7 @@ video/ # standalone Remotion project (spec-v7-intro-video), a pnpm work
- Site identity is deployment-time configuration, not a repo literal: `SITE_URL` / `SITE_NAME` are GitHub **repository variables** (`vars.` context — public values, not secrets) passed as job env to `build` and `generate-resume`; locally they live in the uncommitted `.env` (template `.env.example`). A production build without them fails with an error naming the variable
- The stack directory and the container name are deployment-time configuration as well: both workflows read the stack path from the repository variable `STACK_DIR` — absolute, **no trailing slash**, because the jobs append `/dist/` and `/` themselves — and the infra job reads the compose service / container name it recreates and probes from `CONTAINER_NAME`. Each job refuses a bad value in its first step, before any artifact download or rsync reaches the VPS, and the infra guard greps `compose.yaml` so `CONTAINER_NAME` cannot disagree with the service and `container_name` this repository declares (spec-v6 D15)
- Three jobs: `build` (`pnpm build` → `dist/` artifact) → `generate-resume` (`pnpm tsx scripts/generate-resume.ts --lang=en`, then `--lang=vi`) → `deploy` rsyncs `dist/`, both PDFs included, to `${{ vars.STACK_DIR }}/dist/`
- `nginx.conf` also carries the SEO/security layer (spec-v8): `location /` resolves each URL against its generated file — `try_files $uri/index.html $uri =404` (the composite first parameter is deliberate: a bare `$uri`/`$uri/` on a directory makes nginx 301 `/about` → `/about/`, which would break canonical/sitemap/internal-link identity) — so known routes serve 200 at the exact URL and unknown URLs get a genuine 404 answered by `dist/404.html` via a server-level `error_page`; the six security headers (`X-Content-Type-Options`, `Referrer-Policy`, `X-Frame-Options: DENY`, `Permissions-Policy`, HSTS, and a CSP **in Report-Only form** — enforcing after the owner observes `Report-Only-Violation` reports, D5; its `script-src` hashes must match the inline scripts, guarded by `generate-route-pages.ts`) are server-level so they cover every response including 404s; `gzip on` with explicit `gzip_types` (CSS/JS/JSON/SVG/XML — HTML is nginx's always-on default type; the already-compressed images/PDFs/video are not types) compresses the transferred bodies
- `nginx.conf` — production Nginx SPA routing + caching config + the `/api/content/` location: auth_basic (`/etc/nginx/htpasswd` — the file is **not committed**: `deploy-infra.yml` writes it on the VPS from the `HTPASSWD_CONTENT` repository secret, spec-v6 D16) in front of a proxied Contents API, proxied to it over HTTP/2 (`proxy_http_version 2` + a cleared `Connection` header, spec-v4 D14, verified against `api.github.com` 2026-10-26; the stack's nginx 1.31.x already caches upstream connections by default since 1.29.7, so no `upstream` block is declared, and the template carries only `${CONTENT_API_BASE}` and `Bearer ${CONTENT_API_TOKEN}` — the token and the git host never enter the SPA bundle or the repository). The image's envsubst step renders the template **before nginx parses it**, so `proxy_pass` is a literal upstream rather than an nginx variable — the reason the location-prefix → directive-URI mapping works and the reason a placeholder in `proxy_pass` must be a resolvable literal IP (spec-v6 D4a)
- `compose.yaml` — the stack definition for local AND VPS use (repo copy == stack copy): runtime values live in `secrets/site_config` (gitignored file in the stack directory, two lines `CONTENT_API_TOKEN=` / `CONTENT_API_BASE=`, chmod 600), sourced by an entrypoint override (`set -a` + inline `nginx -g 'daemon off;'` — a compose entrypoint override drops the image's CMD) before the official entrypoint renders the template; the stack directory has no `.env`. On the VPS the same stack is managed by **Dockge** (upstream; stacks dir `/opt/stacks`, stack file `/opt/stacks/dong-site/compose.yaml`) — the repository is the single source of truth for `nginx.conf` / `compose.yaml`; `deploy/htpasswd` is the exception (spec-v6 D16): it is gitignored, lives only on the server (written by the infra job from the `HTPASSWD_CONTENT` secret) and as an untracked local copy for the local compose mount
- `compose.override.yaml` — local-only, auto-merged by `docker compose`, never rsynced by the pipeline: publishes the container on `127.0.0.1:8081` so the production stack can be browsed locally; the VPS stack is unaffected
@@ -221,6 +224,7 @@ All specification documents are in `docs/design/`:
| `specs/v4/spec-v4-*.md` | v4 feature specs (i18n locale overlay, git-backed live edit with preview, authenticated Contents-API write path; supersedes v3-i18n Phase 2). `spec-v4-data-organization.md`: per-entity content files, per-page field-level manifests, per-feature-group UI — implemented 2026-10-23 (automated checks pass; browser walkthrough pending). `spec-v4-inline-editing.md`: edit everything on the page (pencil-icon triggers, tag chips, record add/delete/move, settings popover), JSON panel deleted — implemented 2026-10-23; it supersedes live-edit §5.1/§5.4 panel scope. `spec-v4-deploy-infra.md`: pipeline redeploy of the VPS nginx container, Dockge-managed stack (paths-filtered `deploy-infra.yml`, test-before-touch, repo-as-source-of-truth, token-safety rules) + externalizing site identity — `SITE_URL` / `SITE_NAME` as CI Actions variables, `GITEA_TOKEN` + `GITEA_CONTENTS_API` in the stack's single config file `secrets/site_config` — repo side implemented 2026-10-23 (`deploy-infra.yml`, `compose.yaml` secret + entrypoint override, env-driven identity); owner-side variables/config file + first verified run pending |
| `specs/v5/spec-v5-*.md` | v5 feature specs. `spec-v5-generated-content-ids.md`: the content id unions and the project category values are generated from the structure documents (`scripts/generate-content-types.ts`, run by `predev` / `prebuild` / `prepare`), edit mode writes JSON only, validator rule 7 requires a label for every used category in both languages — implemented 2026-10-24; it supersedes the id-union legs of `spec-v4-live-edit.md` §3.1 |
|`specs/v7/spec-v7-*.md`|v7 feature specs. `spec-v7-intro-video.md`: the 62-second Remotion-rendered explainer (`video/` workspace member → `public/media/`) shown on the new `/how-it-works` page — route, manifest, `howItWorks` UI group, EN/VI caption tracks, chapter seeking; the optional captured-footage variant awaits owner screen recordings — implemented 2026-10-28 (automated checks pass; browser walkthrough pending)|
|`specs/v8/spec-v8-*.md`|v8 feature specs. `spec-v8-seo-hardening.md`: response to the 2026-10-29 site audit — build-time per-route HTML (`scripts/generate-route-pages.ts` rewrites the built head per route: page-specific title/description/canonical/og from the `meta` UI group or the project records, manifest-claimed `<noscript>` content, generated `404.html`), genuine nginx 404s (`try_files $uri/index.html $uri =404`), six security headers with CSP in Report-Only form + gzip, sitemap `lastmod` from git, H1 hierarchy + diagram `<pre>` rendering + og:image dimensions — implemented 2026-10-29 (repo side; nginx end-to-end verified in a 1.31 container; browser walkthrough + CSP enforcement decision owner-side)|
|`specs/v6/spec-v6-*.md`|v6 feature specs. `spec-v6-github-actions.md`: both pipelines move to GitHub Actions and the repository becomes GitHub-primary, the write-path values are renamed `CONTENT_API_TOKEN` / `CONTENT_API_BASE` with a `Bearer` upstream header, `draft.ts` learns GitHub's 409 conflict answer, the site keeps its VPS/nginx/Dockge host and its three-job pipeline, and the Basic-auth file leaves the repository — `deploy/htpasswd` is gitignored, the infra job writes it on the VPS from the `HTPASSWD_CONTENT` repository secret (D16, 2026-10-28) — repo side implemented 2026-10-26 (owner-side GitHub variables/secrets, the VPS `secrets/site_config` rewrite and the first verified run are open); it supersedes the CI-host legs of `spec-v4-deploy-infra.md` and the Contents-API status codes of `spec-v4-live-edit.md` §6.1|
Read `spec.md` first for product context. Read `spec-v2.md` for current feature scope.