-
Notifications
You must be signed in to change notification settings - Fork 149
82 lines (74 loc) · 2.73 KB
/
deploy-website.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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'