完全版 HTML を GitHub Pages の /dist/ で配信する#34
Merged
Conversation
## 何をしているか
main への push で `python build.py` を CI で実行し、生成された
完全版 HTML (`dist/*.html`) を既存リポと一緒に Pages にデプロイ。
これまで「ローカルでビルドして手動配布」だった完全版が、Pages 上の
URL(`co-lect.github.io/lectures/dist/<章名>.html`)として常に
最新版が公開され、右クリック → 保存でダウンロードできるようになる。
## 変更
- `.github/workflows/pages-deploy.yml` (新規)
- main push でビルド + デプロイ。PR では build-only で破損検出
- `_site/` に編集用(リポ全体)+ 完全版(`dist/*.html`)を rsync で詰める
- 既存の編集用 URL(章フォルダ、`shared/`、`sitemap.xml` 等)は維持
- `build.py`
- 完全版 HTML の `</head>` 直前に `<link rel="canonical">` と
`<meta name="robots" content="noindex, follow">` を自動挿入
- 重複コンテンツ対策。検索エンジンには編集用 URL を正本として扱わせる
- `README.md`
- 「完全版を入手する」セクションを Pages 経由のダウンロード手順に拡張
- 取り扱い注意(dist/ を直接編集しない・force-add しない)を明文化
## 設計判断
- **`_site` パターン採用**: Pages 設定を「Actions」に切り替えると、
artifact に含めなかった既存 URL は消える。rsync で `.git` `.github`
`dist` `_site` のみ除外して残りを全部 `_site/` に入れることで、
編集用 URL の互換性を保つ
- **`dist/` は引き続き git 管理外**: CI が生成・配信するため、リポに
入れる必要なし。PR #12 で確立した不変条件を維持
- **canonical/noindex を build.py 側で注入**: ワークフローではなく
ビルドスクリプトで仕込むことで、ローカルビルドした完全版にも同じ
メタが入る(手元配布版でも検索エンジン的に安全)
- **PR ジョブは build-only**: 外部 PR で deploy 権限を持たせない
## デプロイ前に必要な手動作業
Settings → Pages → Source を「GitHub Actions」に切り替える必要あり
(現状は「Deploy from a branch」想定)。切替後は本ワークフローが
唯一のデプロイ経路になる。
## 動作確認(ローカル)
- `python build.py` で 4 章すべて [OK]、size 妥当
- 全章に canonical / robots=noindex が `</head>` 直前に挿入されることを確認
Closes #33
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.github/workflows/pages-deploy.ymlを新規追加し、main push で完全版 HTML を Pages に自動デプロイbuild.pyが完全版 HTML に<link rel=\"canonical\">と<meta name=\"robots\" content=\"noindex, follow\">を自動注入(重複コンテンツ対策)README.mdに Pages 経由のダウンロード手順と取り扱い注意を追記なぜ
PR #12 で
build.pyを導入したが、dist/は.gitignore済みで配布は手動だった。「ダウンロードしてダブルクリックで開ける単体 HTML」を、ビルドできない人にも届けるには Pages で URL を渡せる形が必要。設計判断
_siteパターン: Pages 設定を「Branch」→「Actions」に切り替えた瞬間、artifact に含めなかった既存 URL が消える。rsync で既存リポ全体を_site/に詰め、dist/を追加配信build.py側で注入: ワークフローではなくビルドスクリプトに仕込むことで、ローカルビルドの完全版にも同じメタが入るdist/は引き続き git 管理外: PR 完全版(単一ファイル)ビルドスクリプトを追加 #12 の不変条件を維持必要な手動作業(マージ前後)
Settings → Pages → Source を「GitHub Actions」に切り替える 必要があります(現状は「Deploy from a branch」想定)。切替前は workflow が動いても deploy 段階で失敗します。
Test plan
python build.pyで 4 章すべて [OK]、canonical / robots=noindex が全章の</head>直前に挿入されることを確認co-lect.github.io/lectures/01-claude-code-intro/の編集用 URL が引き続き 200 を返すco-lect.github.io/lectures/dist/01-claude-code-intro.htmlが完全版 HTML を返すview-sourceで canonical と robots meta が確認できるCloses #33
🤖 Generated with Claude Code