Skip to content

Commit 3e8f8a5

Browse files
committed
docs: Add 404 Redirect
1 parent 630136b commit 3e8f8a5

File tree

5 files changed

+110
-149
lines changed

5 files changed

+110
-149
lines changed

.github/scripts/deploy-404.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
# Exit immediately if a command exits with a non-zero status.
4+
set -e
5+
6+
# This script deploys the custom 404.html page to the root of the gh-pages branch.
7+
# It's designed to be called from the GitHub Actions workflow.
8+
#
9+
# It expects one argument:
10+
# $1: The GitHub repository name (e.g., "a2aproject/A2A").
11+
#
12+
# The script assumes that the git user name and email are already configured.
13+
14+
# --- Validate Input ---
15+
if [ -z "$1" ]; then
16+
echo "Error: Missing required argument. Please provide the repository name (e.g., owner/repo)."
17+
exit 1
18+
fi
19+
20+
REPO_NAME=$1
21+
22+
echo "Deploying custom 404 page for repository: $REPO_NAME"
23+
24+
# --- Deployment Logic ---
25+
# Clone the gh-pages branch into a temporary directory
26+
git clone --branch=gh-pages --single-branch --depth=1 "https://github.com/${REPO_NAME}" gh-pages-deploy
27+
28+
# Copy the 404 page from the main branch checkout into the gh-pages clone
29+
cp docs/404.html gh-pages-deploy/404.html
30+
31+
# Navigate into the cloned directory
32+
cd gh-pages-deploy
33+
34+
# Add the 404 page to the staging area
35+
git add 404.html
36+
37+
# Commit and push only if the 404 page has actually changed
38+
if git diff --staged --quiet; then
39+
echo "404.html is up-to-date. No new commit needed."
40+
else
41+
echo "Committing and pushing updated 404.html..."
42+
git commit -m "docs: deploy custom 404.html for redirects"
43+
git push
44+
fi
45+
46+
echo "404 page deployment complete."

.github/workflows/docs.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- main
77
paths:
88
- ".github/workflows/docs.yml"
9+
- ".github/scripts/deploy-404.sh"
910
- "requirements-docs.txt"
1011
- "mkdocs.yml"
1112
- "docs/**"
@@ -14,6 +15,7 @@ on:
1415
- main
1516
paths:
1617
- ".github/workflows/docs.yml"
18+
- ".github/scripts/deploy-404.sh"
1719
- "requirements-docs.txt"
1820
- "mkdocs.yml"
1921
- "docs/**"
@@ -34,6 +36,7 @@ jobs:
3436
- name: Checkout Code
3537
uses: actions/checkout@v4
3638
with:
39+
token: ${{ secrets.GITHUB_TOKEN }}
3740
fetch-depth: 0
3841

3942
- name: Configure Git Credentials
@@ -64,8 +67,13 @@ jobs:
6467
- name: Deploy development version from main branch
6568
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
6669
run: |
67-
echo "Deploying docs from main to the 'dev' version..."
68-
mike deploy --push --update-aliases dev
70+
mike deploy --push --update-aliases dev latest
71+
72+
echo "Setting 'latest' as the default version for the site..."
73+
mike set-default --push latest
74+
75+
# Deploy 404 page
76+
bash .github/scripts/deploy-404.sh ${{ github.repository }} ${{ secrets.GITHUB_TOKEN }}
6977
7078
- name: Deploy new release version and set as latest
7179
if: github.event_name == 'release'
@@ -77,3 +85,6 @@ jobs:
7785
7886
echo "Setting 'latest' as the default version for the site..."
7987
mike set-default --push latest
88+
89+
# Call the reusable script to deploy the 404 page, passing the token
90+
bash .github/scripts/deploy-404.sh ${{ github.repository }} ${{ secrets.GITHUB_TOKEN }}

docs/404.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>Redirecting...</title>
7+
<script>
8+
(function () {
9+
const basePath = '/A2A/';
10+
const latestVersion = 'latest';
11+
12+
const path = window.location.pathname;
13+
const redirected = sessionStorage.getItem('redirected');
14+
15+
if (redirected) {
16+
sessionStorage.removeItem('redirected');
17+
console.warn('Redirect loop detected. Stopping redirect.');
18+
return;
19+
}
20+
21+
// Check if the path is an asset or already a versioned path
22+
const isAsset = path.includes('/assets/') || path.includes('/stylesheets/');
23+
const isVersioned = new RegExp(`${basePath}(v?(\d+\.\d+(\.\d+)?)|${latestVersion})/`).test(path);
24+
25+
if (!isVersioned && !isAsset) {
26+
// Construct the new URL.
27+
// Example: /A2A/specification.md -> /A2A/latest/specification.md
28+
const newPath = path.replace(basePath, basePath + latestVersion + '/');
29+
30+
// Store a marker in sessionStorage to prevent loops
31+
sessionStorage.setItem('redirected', 'true');
32+
33+
// Perform the redirect
34+
window.location.replace(newPath + window.location.search + window.location.hash);
35+
} else {
36+
window.location.replace("https://a2aproject.github.io/A2A/");
37+
}
38+
})();
39+
</script>
40+
</head>
41+
42+
<body>
43+
<h1>Page Not Found</h1>
44+
<p>We are attempting to redirect you to the latest version of this page.</p>
45+
<p>If you are not redirected automatically, please navigate to the <a href="/A2A/">project homepage</a>.</p>
46+
</body>
47+
48+
</html>

mkdocs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ site_description: >-
66
site_dir: site
77

88
extra:
9-
a2a_version: !ENV [MIKE_VERSION, 'local-dev']
9+
a2a_version: !ENV [MIKE_VERSION, 'dev']
1010

1111
# Navigation
1212
nav:
@@ -140,8 +140,7 @@ plugins:
140140
- redirects:
141141
redirect_maps:
142142
"spec-json.md": https://raw.githubusercontent.com/a2aproject/A2A/refs/heads/main/specification/json/a2a.json
143-
"specification/overview.md": "latest/specification.md"
144-
"robots.txt": "v0.2.5/robots.txt"
143+
"specification/overview.md": "specification.md"
145144
"specification/agent-card.md": "specification.md#5-agent-discovery-the-agent-card"
146145
"specification/agent-to-agent-communication.md": "specification.md#6-protocol-data-objects"
147146
"specification/sample-messages.md": "specification.md#9-common-workflows-examples"
@@ -188,6 +187,7 @@ plugins:
188187
- ".ruff_cache"
189188
- "node_modules"
190189
- "__pycache__"
190+
- ".DS_Store"
191191
extra:
192192
show_value: true
193193
show_qualifiers: false

noxfile.py

Lines changed: 0 additions & 144 deletions
This file was deleted.

0 commit comments

Comments
 (0)