Skip to content

Commit b6508e5

Browse files
docs: Add redirect page (#64)
We need an `index.html` file in the root of the repo on the `gh-pages` branch. This way, if a customer ends up at `.../core`, we can redirect to `.../core/main` so our customer does not receive a 404. Co-authored-by: Karl Higley <kmhigley@gmail.com>
1 parent 3ba6274 commit b6508e5

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

.github/workflows/docs-sched-rebuild.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,46 @@ jobs:
7272
echo "Git adding ${i}"
7373
git add "${i}"
7474
done
75+
- name: Check or create dot-no-jekyll file
76+
run: |
77+
if [ -f ".nojekyll" ]; then
78+
echo "The dot-no-jekyll file already exists."
79+
exit 0
80+
fi
81+
touch .nojekyll
82+
git add .nojekyll
83+
- name: Check or create redirect page
84+
env:
85+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
run: |
87+
resp=$(grep 'http-equiv="refresh"' index.html 2>/dev/null) || true
88+
if [ -n "${resp}" ]; then
89+
echo "The redirect file already exists."
90+
exit 0
91+
fi
92+
# If any of these commands fail, fail the build.
93+
def_branch=$(gh api "repos/${GITHUB_REPOSITORY}" --jq ".default_branch")
94+
html_url=$(gh api "repos/${GITHUB_REPOSITORY}/pages" --jq ".html_url")
95+
# Beware ugly quotation mark avoidance in the foll lines.
96+
echo '<!DOCTYPE html>' > index.html
97+
echo '<html>' >> index.html
98+
echo ' <head>' >> index.html
99+
echo ' <title>Redirect to documentation</title>' >> index.html
100+
echo ' <meta charset="utf-8">' >> index.html
101+
echo ' <meta http=equiv="refresh" content="3; URL='${html_url}${def_branch}'/index.html">' >> index.html
102+
echo ' <link rel="canonical" href="'${html_url}${def_branch}'/index.html">' >> index.html
103+
echo ' <script language="javascript">' >> index.html
104+
echo ' function redirect() {' >> index.html
105+
echo ' window.location.assign("'${html_url}${def_branch}'/index.html")' >> index.html
106+
echo ' }' >> index.html
107+
echo ' </script>' >> index.html
108+
echo ' </head>' >> index.html
109+
echo ' <body onload="redirect()">' >> index.html
110+
echo ' <p>Please follow the link to the <a href="'${html_url}${def_branch}'/index.html">' >> index.html
111+
echo ${def_branch}'</a> branch documentation.</p>' >> index.html
112+
echo ' </body>' >> index.html
113+
echo '</html>' >> index.html
114+
git add index.html
75115
- name: Commit changes to the GitHub Pages branch
76116
run: |
77117
git status

0 commit comments

Comments
 (0)