--- layout: default title: "GitHub Pages完全ガイド" description: "高機能Webサイト構築とGitHub Pages完全活用法" --- # 🌐 GitHub Pages - 高機能Webサイト・ドキュメント公開 GitHub Pagesを活用して、WordPress・Netlify・Vercel等の外部ホスティングサービスに依存しない、統合されたWebサイト・ドキュメント公開環境を構築する完全ガイド。静的サイトから動的機能まで、企業レベルのWeb公開を実現します。 ## 🎯 学習目標 - GitHub Pages の全機能理解と戦略的活用 - Jekyll・Hugo・Next.js等の静的サイトジェネレーター完全活用 - カスタムドメイン・SSL・CDN設定による本格運用 - 外部ホスティングサービスからの移行戦略 - 高度なWebサイト自動化・運用最適化 ## 📚 目次 1. [GitHub Pages 概要](#1-github-pages-概要) 2. [静的サイトジェネレーター活用](#2-静的サイトジェネレーター活用) 3. [高度なWebサイト構築](#3-高度なwebサイト構築) 4. [カスタムドメイン・SSL設定](#4-カスタムドメインssl設定) 5. [外部サービスからの移行](#5-外部サービスからの移行) 6. [運用最適化・監視](#6-運用最適化監視) --- ## 1. GitHub Pages 概要 ### 🏗️ GitHub Pages アーキテクチャ #### デプロイメント戦略比較 ```mermaid graph TB A[GitHub Pages デプロイメント戦略] A --> B[Classic Pages] A --> C[GitHub Actions] B --> B1[直接ブランチ] B --> B2[docs/ フォルダ] C --> C1[カスタムビルド] C --> C2[複数言語対応] C --> C3[高度な前処理] style C fill:#e1f5fe style C1 fill:#e8f5e8 style C2 fill:#e8f5e8 style C3 fill:#e8f5e8 ``` #### 機能比較マトリックス ```markdown ### GitHub Pages vs 外部ホスティング比較 | 機能 | GitHub Pages | Netlify | Vercel | WordPress.com | 備考 | |------|--------------|---------|--------|---------------|------| | **基本ホスティング** | ✅ 無料 | ✅ 無料枠 | ✅ 無料枠 | ⚠️ 有料 | GitHubは無制限 | | **カスタムドメイン** | ✅ | ✅ | ✅ | ✅ | 全て対応 | | **SSL証明書** | ✅ 自動 | ✅ 自動 | ✅ 自動 | ✅ 自動 | Let's Encrypt | | **CDN配信** | ✅ | ✅ | ✅ | ✅ | 全世界配信 | | **ビルド統合** | ✅ Actions | ✅ | ✅ | ❌ | GitHubが最も柔軟 | | **Git統合** | ✅ ネイティブ | ✅ | ✅ | ⚠️ 部分的 | GitHubが最も深い統合 | | **コスト(月額)** | $0 | $0-19 | $0-20 | $4-25 | GitHubが最もコスト効率 | | **帯域制限** | 100GB/月 | 100GB/月 | 100GB/月 | 無制限 | 個人・小規模には十分 | | **ストレージ** | 1GB | 無制限 | 無制限 | 3-200GB | 静的サイトには十分 | ``` ### 🚀 GitHub Pages 設定戦略 #### レポジトリタイプ別設定 ```yaml # GitHub Pages 設定パターン ## パターン1: ユーザー/組織サイト Repository: username.github.io URL: https://username.github.io Branch: main (ルートディレクトリ) Use Case: 個人ポートフォリオ、企業メインサイト ## パターン2: プロジェクトサイト Repository: any-repo-name URL: https://username.github.io/repo-name Branch: main, gh-pages, または docs/ Use Case: プロジェクトドキュメント、製品サイト ## パターン3: カスタムドメイン Repository: any-repo-name URL: https://custom-domain.com Branch: 任意 Custom Domain: CNAME設定 Use Case: 企業サイト、ブランドサイト ``` --- ## 2. 静的サイトジェネレーター活用 ### 🎨 Jekyll 高度活用 #### 企業レベルJekyllサイト ```yaml # _config.yml - 高度なJekyll設定 title: "Enterprise Documentation Hub" description: "Complete technical documentation and API reference" url: "https://docs.company.com" baseurl: "" # 高度な設定 timezone: Asia/Tokyo encoding: utf-8 permalink: /:categories/:year/:month/:day/:title/ # プラグイン設定 plugins: - jekyll-feed - jekyll-sitemap - jekyll-seo-tag - jekyll-redirect-from - jekyll-archives - jekyll-paginate-v2 - jekyll-compress-images - jekyll-minifier # SEO設定 seo: name: "Company Name" type: "Organization" links: - "https://twitter.com/company" - "https://linkedin.com/company/company" # パフォーマンス最適化 compress_html: clippings: all comments: all endings: all ignore: envs: [development] # 多言語対応 languages: ["en", "ja", "zh"] default_lang: "en" exclude_from_localizations: ["assets", "admin"] # Collections設定 collections: api: output: true permalink: /:collection/:name/ tutorials: output: true permalink: /:collection/:categories/:title/ case_studies: output: true permalink: /:collection/:year/:month/:title/ # デフォルト設定 defaults: - scope: path: "" type: "posts" values: layout: "post" author: "Tech Team" categories: ["blog"] - scope: path: "" type: "api" values: layout: "api" sidebar: "api" - scope: path: "" type: "tutorials" values: layout: "tutorial" sidebar: "tutorials" # ビルド設定 safe: true incremental: true keep_files: [".git", ".svn"] markdown: kramdown highlighter: rouge # Kramdown設定 kramdown: input: GFM syntax_highlighter: rouge syntax_highlighter_opts: css_class: 'highlight' span: line_numbers: false block: line_numbers: true # Sass設定 sass: style: compressed sass_dir: _sass ``` #### 高機能Jekyllテーマ構築 ```html
{% seo %} {% if site.google_analytics %} {% endif %} Skip to main content {% include header.html %}No results found
'; return; } const resultsList = results.map(result => `${result.path}
Repository: ${result.repository.full_name}]*>(.*?)', r'`\1`'),
(r']*href="([^"]*)"[^>]*>(.*?)', r'[\2](\1)'),
(r']*>(.*?)
', r'\1\n\n'), (r']*>(.*?)', r'> \1\n'), ] for pattern, replacement in conversions: content = re.sub(pattern, replacement, content, flags=re.DOTALL | re.IGNORECASE) # 残りのHTMLタグを除去 content = re.sub(r'<[^>]+>', '', content) # 余分な空行を整理 content = re.sub(r'\n\s*\n\s*\n', '\n\n', content) return content.strip() # 使用例 if __name__ == "__main__": converter = WordPressToJekyll('wordpress-export.xml', 'jekyll-site') converter.convert() print("WordPress to Jekyll conversion completed!") ``` ### 📊 移行比較・ROI計算 #### コスト・機能比較分析 ```markdown ## WordPress.com → GitHub Pages 移行分析 ### 📊 年間コスト比較(企業サイト想定) | 項目 | WordPress.com | GitHub Pages | 節約額 | |------|---------------|--------------|--------| | **ホスティング** | $300/年 | $0/年 | $300 | | **カスタムドメイン** | $18/年 | $12/年 | $6 | | **SSL証明書** | 含む | $0(無料) | $0 | | **CDN** | $0-200/年 | $0(含む) | $200 | | **バックアップ** | $120/年 | $0(Git) | $120 | | **テーマ・プラグイン** | $200/年 | $0(カスタム) | $200 | | **メンテナンス** | $600/年 | $100/年 | $500 | | **セキュリティ** | $180/年 | $0(標準) | $180 | **年間総コスト**: - WordPress.com: $1,418/年 - GitHub Pages: $112/年 - **年間節約額: $1,306 (92%削減)** ### 🚀 パフォーマンス比較 | 指標 | WordPress.com | GitHub Pages | 改善 | |------|---------------|--------------|------| | **読み込み速度** | 2.5秒 | 0.8秒 | 68%向上 | | **Lighthouse Score** | 75/100 | 98/100 | 31%向上 | | **稼働率** | 99.9% | 99.95% | 0.05%向上 | | **CDN配信** | 地域限定 | 全世界 | グローバル | | **キャッシュ効率** | 中 | 高 | 大幅改善 | ### ✅ 機能比較 | 機能 | WordPress.com | GitHub Pages | 移行可否 | |------|---------------|--------------|----------| | **ブログ機能** | ✅ | ✅ Jekyll | ✅ | | **CMS管理** | ✅ Web UI | ⚠️ Git/Markdown | 代替可能 | | **コメント機能** | ✅ | ⚠️ 外部サービス | 代替可能 | | **検索機能** | ✅ | ⚠️ JavaScript実装 | 実装可能 | | **フォーム** | ✅ | ⚠️ 外部サービス | 代替可能 | | **eコマース** | ✅ | ❌ | 別途必要 | | **マルチユーザー** | ✅ | ⚠️ Git権限管理 | 代替可能 | | **バックアップ** | ✅ | ✅ Git | 同等以上 | | **バージョン管理** | ⚠️ | ✅ Git | 大幅改善 | | **セキュリティ** | ⚠️ | ✅ GitHub | 改善 | ``` --- ## 6. 運用最適化・監視 ### 📊 パフォーマンス監視 #### 包括的サイト監視 ```yaml # .github/workflows/site-monitoring.yml name: Site Performance Monitoring on: schedule: - cron: '0 */6 * * *' # 6時間毎 workflow_dispatch: jobs: lighthouse-audit: name: Lighthouse Performance Audit runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '18' - name: Install Lighthouse CI run: npm install -g @lhci/cli - name: Run Lighthouse run: | lhci autorun \ --collect.url=https://username.github.io \ --collect.url=https://username.github.io/docs/ \ --collect.url=https://username.github.io/api/ \ --upload.githubAppToken="${{ secrets.LHCI_GITHUB_APP_TOKEN }}" env: LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }} - name: Generate performance report run: | cat > performance-report.md << 'EOF' # 📊 Performance Monitoring Report **Generated**: $(date -u) **Site**: https://username.github.io ## Lighthouse Scores | Page | Performance | Accessibility | Best Practices | SEO | |------|-------------|---------------|----------------|-----| | Home |  |  |  |  | | Docs |  |  |  |  | | API |  |  |  |  | ## Key Metrics - **First Contentful Paint**: 0.8s - **Largest Contentful Paint**: 1.2s - **Cumulative Layout Shift**: 0.05 - **Time to Interactive**: 1.5s ## Recommendations - ✅ Excellent performance scores - ⚠️ Consider optimizing Best Practices on API page - 🔍 Monitor mobile performance --- *Automated report generated by GitHub Actions* EOF - name: Upload performance artifacts uses: actions/upload-artifact@v3 with: name: performance-report path: | performance-report.md .lighthouseci/ uptime-check: name: Uptime and Health Check runs-on: ubuntu-latest steps: - name: Check site availability run: | urls=( "https://username.github.io" "https://username.github.io/docs/" "https://username.github.io/api/" ) failed_urls=() for url in "${urls[@]}"; do echo "Checking $url..." if ! curl -f -s -o /dev/null -w "%{http_code}" "$url" | grep -E "^(200|301|302)$" > /dev/null; then failed_urls+=("$url") echo "❌ $url is not responding correctly" else echo "✅ $url is healthy" fi done if [ ${#failed_urls[@]} -gt 0 ]; then echo "Failed URLs: ${failed_urls[*]}" exit 1 fi - name: SSL certificate check run: | echo "Checking SSL certificate validity..." domain="username.github.io" expiry_date=$(openssl s_client -servername "$domain" -connect "$domain:443" 2>/dev/null | openssl x509 -noout -dates | grep notAfter | cut -d= -f2) expiry_timestamp=$(date -d "$expiry_date" +%s) current_timestamp=$(date +%s) days_until_expiry=$(( (expiry_timestamp - current_timestamp) / 86400 )) echo "SSL certificate expires on: $expiry_date" echo "Days until expiry: $days_until_expiry" if [ $days_until_expiry -lt 30 ]; then echo "⚠️ SSL certificate expires in less than 30 days!" exit 1 else echo "✅ SSL certificate is valid" fi broken-links-check: name: Broken Links Check runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '18' - name: Install broken-link-checker run: npm install -g broken-link-checker - name: Check for broken links run: | echo "Checking for broken links..." blc https://username.github.io \ --recursive \ --ordered \ --exclude-external \ --filter-level 2 \ --get \ --input - name: Create issue for broken links if: failure() uses: actions/github-script@v6 with: script: | const title = '🔗 Broken Links Detected'; const body = ` ## 🔗 Broken Links Report The automated link checker has detected broken links on the website. **Check Time**: ${new Date().toISOString()} **Workflow**: ${context.workflow} **Run Number**: ${context.runNumber} ### Action Required - [ ] Review the workflow logs for specific broken links - [ ] Fix or remove broken links - [ ] Update redirects if necessary ### Prevention - [ ] Add link validation to CI/CD pipeline - [ ] Regular content audits - [ ] Monitor external dependencies **Auto-generated by**: Site Monitoring Workflow `; await github.rest.issues.create({ owner: context.repo.owner, repo: context.repo.repo, title: title, body: body, labels: ['bug', 'website', 'broken-links'] }); security-headers-check: name: Security Headers Validation runs-on: ubuntu-latest steps: - name: Check security headers run: | echo "Checking security headers..." url="https://username.github.io" headers=$(curl -s -I "$url") # 必須セキュリティヘッダーの確認 required_headers=( "X-Content-Type-Options" "X-Frame-Options" "X-XSS-Protection" "Strict-Transport-Security" ) missing_headers=() for header in "${required_headers[@]}"; do if ! echo "$headers" | grep -i "$header" > /dev/null; then missing_headers+=("$header") fi done if [ ${#missing_headers[@]} -gt 0 ]; then echo "❌ Missing security headers: ${missing_headers[*]}" exit 1 else echo "✅ All required security headers present" fi ``` ### 📈 アクセス解析・最適化 #### Google Analytics 4 統合 ```javascript // assets/js/analytics.js class AdvancedAnalytics { constructor(gaId) { this.gaId = gaId; this.isProduction = window.location.hostname !== 'localhost'; this.init(); } init() { if (!this.isProduction || !this.gaId) return; // Google Analytics 4 の読み込み this.loadGA4(); // カスタムイベントの設定 this.setupCustomEvents(); // パフォーマンス監視 this.setupPerformanceTracking(); // エラー追跡 this.setupErrorTracking(); } loadGA4() { // GA4 スクリプトの動的読み込み const script = document.createElement('script'); script.async = true; script.src = `https://www.googletagmanager.com/gtag/js?id=${this.gaId}`; document.head.appendChild(script); window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', this.gaId, { // プライバシー設定 anonymize_ip: true, cookie_flags: 'SameSite=Strict;Secure', // パフォーマンス監視 custom_map: { 'custom_parameter_1': 'page_load_time', 'custom_parameter_2': 'user_engagement' } }); window.gtag = gtag; } setupCustomEvents() { // 外部リンククリック追跡 document.addEventListener('click', (e) => { const link = e.target.closest('a'); if (link && link.hostname !== window.location.hostname) { this.trackEvent('click', { event_category: 'external_link', event_label: link.href, transport_type: 'beacon' }); } }); // ダウンロード追跡 document.addEventListener('click', (e) => { const link = e.target.closest('a'); if (link && this.isDownloadLink(link.href)) { this.trackEvent('file_download', { file_name: this.getFileName(link.href), file_extension: this.getFileExtension(link.href), transport_type: 'beacon' }); } }); // スクロール深度追跡 this.setupScrollTracking(); // 検索イベント追跡 const searchInput = document.getElementById('site-search'); if (searchInput) { searchInput.addEventListener('search', (e) => { this.trackEvent('search', { search_term: e.target.value, event_category: 'site_search' }); }); } } setupScrollTracking() { let scrollDepths = [25, 50, 75, 90]; let trackedDepths = new Set(); window.addEventListener('scroll', () => { const scrollPercent = Math.round( (window.scrollY / (document.body.scrollHeight - window.innerHeight)) * 100 ); scrollDepths.forEach(depth => { if (scrollPercent >= depth && !trackedDepths.has(depth)) { trackedDepths.add(depth); this.trackEvent('scroll', { event_category: 'engagement', event_label: `${depth}%`, value: depth }); } }); }); } setupPerformanceTracking() { // Core Web Vitals 監視 if ('web-vital' in window) { import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { getCLS(this.sendWebVital.bind(this)); getFID(this.sendWebVital.bind(this)); getFCP(this.sendWebVital.bind(this)); getLCP(this.sendWebVital.bind(this)); getTTFB(this.sendWebVital.bind(this)); }); } // Navigation Timing API window.addEventListener('load', () => { setTimeout(() => { const timing = performance.getEntriesByType('navigation')[0]; if (timing) { this.trackEvent('page_timing', { event_category: 'performance', page_load_time: Math.round(timing.loadEventEnd - timing.fetchStart), dom_ready_time: Math.round(timing.domContentLoadedEventEnd - timing.fetchStart), first_byte_time: Math.round(timing.responseStart - timing.fetchStart) }); } }, 1000); }); } sendWebVital(metric) { this.trackEvent(metric.name, { event_category: 'web_vitals', value: Math.round(metric.value), metric_id: metric.id, metric_delta: metric.delta }); } setupErrorTracking() { // JavaScript エラー追跡 window.addEventListener('error', (e) => { this.trackEvent('exception', { description: `${e.message} at ${e.filename}:${e.lineno}:${e.colno}`, fatal: false, error_type: 'javascript_error' }); }); // Promise rejection 追跡 window.addEventListener('unhandledrejection', (e) => { this.trackEvent('exception', { description: `Unhandled Promise Rejection: ${e.reason}`, fatal: false, error_type: 'promise_rejection' }); }); } trackEvent(eventName, parameters = {}) { if (!this.isProduction || typeof gtag === 'undefined') return; gtag('event', eventName, { event_timestamp: Date.now(), page_title: document.title, page_location: window.location.href, ...parameters }); } isDownloadLink(href) { const downloadExtensions = /\.(pdf|doc|docx|xls|xlsx|ppt|pptx|zip|rar|mp3|mp4|avi|mov)$/i; return downloadExtensions.test(href); } getFileName(href) { return href.split('/').pop().split('?')[0]; } getFileExtension(href) { return href.split('.').pop().split('?')[0].toLowerCase(); } } // 初期化 document.addEventListener('DOMContentLoaded', () => { const gaId = document.querySelector('meta[name="google-analytics"]')?.content; if (gaId) { new AdvancedAnalytics(gaId); } }); ``` --- ## 🎓 実践演習 ### 演習1: 企業レベルWebサイト構築 1. **多機能サイト** - Jekyll/Hugo/Next.js選択と実装 2. **PWA対応** - Service Worker・Web App Manifest 3. **パフォーマンス最適化** - 画像最適化・CDN活用 4. **SEO対策** - 構造化データ・メタタグ最適化 ### 演習2: 外部サービス移行プロジェクト 1. **現状分析** - WordPress/他サービスの機能調査 2. **移行戦略** - データ移行・機能代替・リスク評価 3. **段階移行** - 並行運用・段階的切り替え 4. **運用最適化** - 監視・メンテナンス・改善 ### 演習3: 高可用性Webサイト運用 1. **監視体制** - パフォーマンス・稼働率・セキュリティ 2. **自動化** - デプロイ・バックアップ・復旧 3. **スケーリング** - CDN・キャッシュ戦略 4. **継続改善** - A/Bテスト・ユーザーフィードバック --- ## 🔗 関連リソース ### 公式ドキュメント - [GitHub Pages Documentation](https://docs.github.com/en/pages) - [Jekyll Documentation](https://jekyllrb.com/docs/) - [Hugo Documentation](https://gohugo.io/documentation/) ### パフォーマンス・SEOツール - [Lighthouse](https://developers.google.com/web/tools/lighthouse) - [PageSpeed Insights](https://pagespeed.web.dev/) - [Web.dev](https://web.dev/) ### 静的サイトジェネレーター - [Gatsby](https://www.gatsbyjs.com/) - [Next.js](https://nextjs.org/docs/advanced-features/static-html-export) - [Nuxt.js](https://nuxtjs.org/docs/get-started/commands#static-deployment) --- ## 📝 まとめ GitHub Pages を効果的に活用することで: ✅ **外部サービス不要** - WordPress・Netlify等からの完全移行 ✅ **コスト大幅削減** - ホスティング・メンテナンス費用の最適化 ✅ **高性能・高可用性** - CDN・SSL・グローバル配信 ✅ **統合開発環境** - コードとWebサイトの一元管理 ✅ **スケーラビリティ** - 企業レベルの大規模サイト対応 これで主要なGitHub機能ガイドが完成しました!次はケーススタディとトレーニング資料を作成しましょう。 ## 🔗 関連ガイド - **前のステップ**: [GitHub Security編](06-github-security.md) - セキュアなWebサイト・セキュリティ強化 - **基礎知識**: [GitHub Actions編](05-github-actions.md) - CI/CDパイプライン構築 - **プロジェクト管理**: [GitHub Projects編](04-github-projects.md) - 統合開発管理 - **開発基礎**: [Pull Request編](03-pull-requests.md) - 協調開発・レビュープロセス - **総合ガイド**: [GitHub完全活用ガイド](../GITHUB_COMPLETE_GUIDE.md) - 全機能の詳細解説 ## 📖 学習フロー ```mermaid graph LR A[リポジトリ基礎] --> B[Issues管理] B --> C[Pull Request] C --> D[GitHub Projects] D --> E[GitHub Actions] E --> F[Security] F --> G[Pages] G --> H[完全活用] style A fill:#f3e5f5 style B fill:#f3e5f5 style C fill:#f3e5f5 style D fill:#f3e5f5 style E fill:#f3e5f5 style F fill:#f3e5f5 style G fill:#e1f5fe style H fill:#e8f5e8 ```