AGENT SKILL

github-pages-flat-deploy-subdir-404

A GitHub Pages deploy is green in CI but a linked doc page 404s live — usually a page that lives in a subdirectory (e.g. docs/second-wind/index.html), while top-level docs (docs/machine-setup.html) work fine. Use when a Pages workflow stages a landing page plus companion docs into one flat _site/ root with `cp docs/*.html _site/` and `sed`-rewritten cross-links, and a new subdir page's link breaks after deploy despite the build passing. Root cause is shell-glob semantics (`*.html` doesn't descend into subdirs) combined with a link-rewrite that only touches top-level `_site/*.html`. This is the flat-copy `_site/` deploy model — NOT the git-subtree-split model (see Related).

License 许可
MIT
最近更新
2026-11-07
Stars
★ 1
Forks
1

01 前言 Front Matter

name
github-pages-flat-deploy-subdir-404
description
A GitHub Pages deploy is green in CI but a linked doc page 404s live — usually a page that lives in a subdirectory (e.g. docs/second-wind/index.html), while top-level docs (docs/machine-setup.html) work fine. Use when a Pages workflow stages a landing page plus companion docs into one flat _site/ root with `cp docs/*.html _site/` and `sed`-rewritten cross-links, and a new subdir page's link breaks after deploy despite the build passing. Root cause is shell-glob semantics (`*.html` doesn't descend into subdirs) combined with a link-rewrite that only touches top-level `_site/*.html`. This is the flat-copy `_site/` deploy model — NOT the git-subtree-split model (see Related).

03 SKILL.md 正文

GitHub Pages flat-deploy: subdirectory pages silently 404

Symptom

CI is green, the artifact uploads, the homepage loads fine — but a specific link 404s on the live site: /second-wind/index.html, or any doc that lives one level deeper than the rest. It only shows up after deploy, never in the build log, because "build succeeded" here just means "the artifact was produced," not "every link in it resolves."

Root cause

Two independent glob blind spots in a workflow that flattens site/ + docs/*.html into one _site/ root and rewrites relative links to work at the flattened depth:

  1. The copy glob skips subdirectories. cp docs/*.html _site/ matches docs/machine-setup.html but not docs/second-wind/index.html — *.html is one directory level, full stop. The page is simply absent from the deployed artifact.
  2. The link-rewrite glob skips subdirectories too. A rewrite such as sed -i 's#\.\./site/index.html#index.html#g' _site/*.html only touches files directly in _site/. Anything copied into _site/<sub>/ never gets rewritten, so ../site/... or ../docs/... back-links inside it stay broken even if you fix (1).

The two compound: the landing page's link ../docs/second-wind/index.html gets flattened by a sed 's#\.\./docs/##g' rewrite to second-wind/index.html — which then has nowhere to resolve, because the copy step never created _site/second-wind/ in the first place.

Fix

Explicitly mkdir + cp each subdirectory (globs won't find them for you), and make the link rewrite recursive so it reaches every staged page:

# WRONG — glob silently drops subdir pages, no error, no CI failure
- name: Stage site
  run: |
    mkdir -p _site
    cp site/index.html _site/index.html
    cp docs/*.html _site/
    sed -i 's#\.\./docs/##g' _site/index.html

# CORRECT — subdirs created and copied explicitly, rewrite is recursive
- name: Stage site
  run: |
    mkdir -p _site _site/second-wind
    cp site/index.html _site/index.html
    # the rewrite below points links at assets/ and the favicons, so those
    # files must be staged too, or every asset link 404s
    cp -r site/assets _site/assets
    cp site/favicon.ico _site/favicon.ico
    cp site/apple-touch-icon.png _site/apple-touch-icon.png
    cp docs/*.html _site/
    # the glob above misses subdirs — create and copy each one explicitly
    cp docs/second-wind/index.html _site/second-wind/index.html
    # (a subdir with assets: cp -r docs/<sub>/img _site/<sub>/img)
    # rewrite every staged page, at any depth. A subdir page keeps its leading
    # ../ (docs/<sub>/x.html links ../../site/assets/ -> ../assets/ after the
    # sed below), so subdir pages can use ../../ links to the shared assets.
    find _site -name '*.html' -print0 | xargs -0 sed -i \
      -e 's#\.\./docs/##g' \
      -e 's#\.\./site/index\.html#index.html#g' \
      -e 's#\.\./site/assets/#assets/#g' \
      -e 's#\.\./site/favicon\.ico#favicon.ico#g' \
      -e 's#\.\./site/apple-touch-icon\.png#apple-touch-icon.png#g'

This repo's own .github/workflows/pages.yml is a working example of only two parts of this shape: the recursive find … | xargs -0 sed -i rewrite and the explicit mkdir per subdir. It still suffixes its optional cp lines with || true, so it is not an example of the no-|| true rule below.

Do not suffix the cp lines with 2>/dev/null || true: it turns a missing source file into a green build with a 404 live, which is this bug again. If a copy is genuinely optional, keep || true only when it is followed by the MISSING-href check below, which fails the job.

Alternative — self-contained subdir pages. If you would rather not rewrite subdir pages at all, make each one self-contained (inline CSS, no ../ back-links or asset paths) so the rewrite never needs to reach it. Confirm with:

grep -n 'href="\.\.\|src="\.\.' docs/<sub>/*.html   # expect no output

Verify before trusting it, two cheap checks:

# A. Locally simulate staging; confirm every flattened href has a matching file.
#    Covers links from the landing page (_site/index.html) only — repeat it
#    per page to cover links from subdir pages. The subshell keeps `exit 1`
#    from closing an interactive zsh; as a CI step it still fails the job.
( grep -oE 'href="[^"]+\.html"' _site/index.html | cut -d'"' -f2 | \
  while read f; do test -f "_site/$f" || { echo "MISSING: $f"; exit 1; }; done )

# B. After deploy, curl every linked path for 200 — not just the homepage
for u in / /machine-setup.html /second-wind/index.html /og.png; do
  echo "$(curl -s -o /dev/null -w '%{http_code}' https://USER.github.io/REPO$u)  $u"
done

Evidence

Found in a Pages workflow that staged a landing page (site/index.html) plus companion docs (docs/*.html) into a flat _site/ root, adding a new doc page nested one directory deeper (docs/second-wind/index.html) that then 404'd live while CI stayed green. The trap is generic shell-glob semantics — *.html never descends into subdirectories — so it reproduces in any rsync/cp-based static-site staging step, not anything GitHub Pages-specific.

Related skills

  • site-pages-deploy-kit — a different deploy model: the site source lives in site/ in the app repo and CI force-pushes a git subtree split of that one directory straight to a public repo's Pages branch. There is no flat _site/ staging step and no cross-directory cp/sed flattening, so this glob-blind-spot bug does not apply there — don't assume subtree deploys need this fix, and don't apply subtree remediation to a flat-copy workflow.
  • site-og-favicon-verify — checks that pages which do deploy render correctly (unfurl/favicon/CSP); orthogonal to whether a page reaches the artifact at all.
  • subpage-nav-anchor-baseurl-ssr-label-drift — the base-path/subdirectory deploy context this bug family lives in; a different failure mode (in-page nav anchors, not the deploy artifact itself) on the same kind of site.

04 同仓库更多 Skills

abhijitbansal
abhijitbansal/claude-skills

second-wind

Orchestrate long unattended Claude Code runs across multiple repos with the wind CLI. Use when the user wants to run Claude Code overnight, resume sessions after the 5-hour usage limit, run Claude in many repos at once via tmux, or says "set up second wind", "wind up", "overnight run", "resume after limit", "usage limit orchestrator".

★ 1
abhijitbansal
abhijitbansal/claude-skills

structured-output-adaptive-thinking-token-bloat

A Claude API call using output_config.format (json_schema structured outputs) with thinking:{type:"adaptive"} burns most of its output budget on thinking (observed ~21k of ~24k tokens) without improving JSON quality, making the run up to ~5x more expensive than the same call with thinking omitted — use when calling the Messages API with a json_schema output format for extraction, ranking, classification, or summarization tasks, or when a schema-constrained call's usage.output_tokens is far larger than the returned JSON.

★ 1
abhijitbansal
abhijitbansal/claude-skills

review

Apply a code-review lens to a diff, branch, or file — find correctness bugs, security issues, and quality problems, ranked by severity, with a concrete fix for each. Use when the user says "review this", "review my diff", "check this PR", "look this over before I commit", or "is this safe". Skip when the user wants the code written, not reviewed.

★ 1
abhijitbansal
abhijitbansal/claude-skills

refresh

Rebuild the prompt-craft command registry and usage profile, and print a summary of installed commands and your personalized recommendations. Use when you install or update plugins and want the advisor to pick them up immediately, or say "refresh prompt-craft", "rebuild the command registry".

★ 1
abhijitbansal
abhijitbansal/claude-skills

refactor

Apply a refactoring lens — restructure code without changing behavior, guarded by tests that pass before and after. Use when the user says "refactor", "clean this up", "extract this", "simplify this", "reduce duplication", or "make this readable" on existing working code. Skip when the change is meant to alter behavior (that's a feature or a fix).

★ 1
abhijitbansal
abhijitbansal/claude-skills

plan

Decompose a non-trivial task into an explicit, tracked plan with goals and per-step acceptance criteria before writing code. Use when the user says "plan this", "break this down", "what's the plan", or asks for a multi-step feature/refactor that touches more than one file. Pairs with plan mode. Skip for single-edit changes that need no decomposition.

★ 1