|
| 1 | +# Clean GitHub Pages Branch Structure |
| 2 | +# |
| 3 | +# This script: |
| 4 | +# 1. Checks out gh-pages branch |
| 5 | +# 2. Keeps only files needed for GitHub Pages |
| 6 | +# 3. Adds a proper README.md explaining the branch purpose |
| 7 | +# 4. Commits the changes |
| 8 | + |
| 9 | +param ( |
| 10 | + [switch]$Force = $false |
| 11 | +) |
| 12 | + |
| 13 | +# Safety check |
| 14 | +if (-not $Force) { |
| 15 | + Write-Host "WARNING: This script will clean up the gh-pages branch, removing files not needed for deployment." -ForegroundColor Yellow |
| 16 | + Write-Host "Files that will be kept:" -ForegroundColor Cyan |
| 17 | + Write-Host "- index.html" -ForegroundColor Cyan |
| 18 | + Write-Host "- assets/ directory" -ForegroundColor Cyan |
| 19 | + Write-Host "- Static assets (images, etc.)" -ForegroundColor Cyan |
| 20 | + Write-Host "- .nojekyll file" -ForegroundColor Cyan |
| 21 | + Write-Host "- README.md" -ForegroundColor Cyan |
| 22 | + Write-Host "" |
| 23 | + Write-Host "All other files will be DELETED!" -ForegroundColor Red |
| 24 | + |
| 25 | + $confirmation = Read-Host "Do you want to continue? (y/n)" |
| 26 | + if ($confirmation -ne 'y') { |
| 27 | + Write-Host "Operation cancelled." -ForegroundColor Red |
| 28 | + exit 0 |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +# Check if we have uncommitted changes |
| 33 | +$status = git status --porcelain |
| 34 | +if ($status) { |
| 35 | + Write-Host "You have uncommitted changes. Please commit or stash them before running this script." -ForegroundColor Red |
| 36 | + exit 1 |
| 37 | +} |
| 38 | + |
| 39 | +# Store current branch |
| 40 | +$currentBranch = git rev-parse --abbrev-ref HEAD |
| 41 | +Write-Host "Current branch: $currentBranch" -ForegroundColor Blue |
| 42 | + |
| 43 | +try { |
| 44 | + # Checkout gh-pages branch |
| 45 | + Write-Host "Checking out gh-pages branch..." -ForegroundColor Blue |
| 46 | + git checkout gh-pages |
| 47 | + |
| 48 | + if ($LASTEXITCODE -ne 0) { |
| 49 | + Write-Host "Failed to checkout gh-pages branch. Aborting." -ForegroundColor Red |
| 50 | + exit 1 |
| 51 | + } |
| 52 | + |
| 53 | + # Create temp directory |
| 54 | + Write-Host "Creating temporary directory..." -ForegroundColor Blue |
| 55 | + $tempDir = ".\.temp\gh-pages-cleanup" |
| 56 | + if (Test-Path $tempDir) { |
| 57 | + Remove-Item -Recurse -Force $tempDir |
| 58 | + } |
| 59 | + New-Item -ItemType Directory -Force -Path $tempDir | Out-Null |
| 60 | + |
| 61 | + # Copy essential files to temp directory |
| 62 | + Write-Host "Copying essential files..." -ForegroundColor Blue |
| 63 | + Copy-Item -Path "index.html" -Destination "$tempDir\" -Force |
| 64 | + Copy-Item -Path ".nojekyll" -Destination "$tempDir\" -Force |
| 65 | + |
| 66 | + # Copy assets directory if it exists |
| 67 | + if (Test-Path "assets") { |
| 68 | + Copy-Item -Path "assets" -Destination "$tempDir\" -Recurse -Force |
| 69 | + } |
| 70 | + |
| 71 | + # Copy other static files that might be needed |
| 72 | + foreach ($dir in @("images", "gatherings", "public", "img", "static", "fonts", "favicon.ico")) { |
| 73 | + if (Test-Path $dir) { |
| 74 | + Write-Host "Copying $dir..." -ForegroundColor Blue |
| 75 | + Copy-Item -Path $dir -Destination "$tempDir\" -Recurse -Force |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + # Download the gh-pages README from the main branch |
| 80 | + Write-Host "Creating README.md for gh-pages..." -ForegroundColor Blue |
| 81 | + $readmePath = "$tempDir\README.md" |
| 82 | + |
| 83 | + # Copy the specialized README or use a basic one |
| 84 | + if (Test-Path "d:\Github_personal\GHPAGES_README.md") { |
| 85 | + Copy-Item -Path "d:\Github_personal\GHPAGES_README.md" -Destination $readmePath -Force |
| 86 | + } else { |
| 87 | + @" |
| 88 | +# Elmentor Landing Page (Deployed Site) |
| 89 | +
|
| 90 | +This branch contains the deployed version of the Elmentor Landing Page website that is served via GitHub Pages. |
| 91 | +
|
| 92 | +## Important Notes |
| 93 | +
|
| 94 | +- This is the **deployment branch** containing only built files |
| 95 | +- Do NOT make direct changes to files in this branch |
| 96 | +- Do NOT merge this branch into the `main` branch |
| 97 | +- All development should occur on the `main` branch |
| 98 | +"@ | Out-File -FilePath $readmePath -Encoding utf8 |
| 99 | + } |
| 100 | + |
| 101 | + # Clean gh-pages branch - remove all files except .git |
| 102 | + Write-Host "Cleaning gh-pages branch..." -ForegroundColor Blue |
| 103 | + Get-ChildItem -Path "." -Exclude @(".git", ".temp") | Remove-Item -Recurse -Force |
| 104 | + |
| 105 | + # Copy files back from temp directory |
| 106 | + Write-Host "Restoring essential files..." -ForegroundColor Blue |
| 107 | + Copy-Item -Path "$tempDir\*" -Destination "." -Recurse -Force |
| 108 | + |
| 109 | + # Stage the changes |
| 110 | + Write-Host "Staging changes..." -ForegroundColor Blue |
| 111 | + git add -A |
| 112 | + |
| 113 | + # Commit the changes |
| 114 | + Write-Host "Committing changes..." -ForegroundColor Blue |
| 115 | + git commit -m "Clean up gh-pages branch structure to DevOps Visions standards" |
| 116 | + |
| 117 | + Write-Host "GH-Pages branch structure has been cleaned up according to DevOps Visions standards." -ForegroundColor Green |
| 118 | + Write-Host "To push these changes to origin, run: git push origin gh-pages" -ForegroundColor Yellow |
| 119 | + |
| 120 | +} catch { |
| 121 | + Write-Host "An error occurred: $_" -ForegroundColor Red |
| 122 | +} finally { |
| 123 | + # Return to original branch |
| 124 | + Write-Host "Returning to $currentBranch branch..." -ForegroundColor Blue |
| 125 | + git checkout $currentBranch |
| 126 | +} |
0 commit comments