Deploy Redirect Page #870
This file contains 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
name: Deploy Redirect Page | |
on: | |
push: | |
branches: [main] | |
paths: | |
- ".github/workflows/deploy-website.yml" | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Check out the repository | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# Step 2: Create redirect HTML files | |
- name: Create redirect HTML | |
run: | | |
mkdir -p dist | |
# Homepage redirect | |
cat > dist/index.html << 'EOF' | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="refresh" content="0; url=https://docs.ag2.ai"> | |
<script>window.location.href = "https://docs.ag2.ai";</script> | |
<title>Page Redirection</title> | |
</head> | |
<body> | |
If you are not redirected automatically, follow this <a href="https://docs.ag2.ai">link to the new documentation</a>. | |
</body> | |
</html> | |
EOF | |
# Deep link handling | |
cat > dist/404.html << 'EOF' | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<script> | |
const newDomain = 'https://docs.ag2.ai'; | |
let path = window.location.pathname; | |
const hash = window.location.hash; | |
// Remove /ag2/ prefix and trailing slash | |
path = path.replace(/^\/ag2\//, '/').replace(/\/$/, ""); | |
// Transform blog and talks URLs | |
if (path.includes('/blog/') || path.includes('/talks/')) { | |
const afterPrefix = path.split(/\/(blog|talks)\//)[2]; | |
const transformed = afterPrefix.replace(/\//g, '-'); | |
path = path.replace(afterPrefix, transformed); | |
} | |
// Handle -index and create final URL with hash | |
const redirectUrl = (newDomain + path).replace(/-index$/, "/index") + hash; | |
window.location.href = redirectUrl; | |
</script> | |
<title>Page Redirection</title> | |
</head> | |
<body> | |
If you are not redirected automatically, follow this <a href="https://docs.ag2.ai">link to the new documentation</a>. | |
</body> | |
</html> | |
EOF | |
# Step 3: Deploy to gh-pages branch | |
- name: Deploy to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./dist | |
force_orphan: true | |
user_name: 'github-actions[bot]' | |
user_email: 'github-actions[bot]@users.noreply.github.com' | |
commit_message: 'Deploy redirect page' |