Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(contrib): generate redirection HTML pages in CI #12846

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/contrib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,23 @@ jobs:
echo `pwd`/mdbook >> $GITHUB_PATH
- name: Deploy docs
run: |
GENERATE_PY="$(pwd)/ci/generate.py"

cd src/doc/contrib
mdbook build

# Override previous ref to avoid keeping history.
git worktree add --orphan -B gh-pages gh-pages
git config user.name "Deploy from CI"
git config user.email ""
cd gh-pages
mv ../book contrib
git add contrib

# Generate HTML for link redirections.
python3 "$GENERATE_PY"
git add *.html
git add CNAME

git commit -m "Deploy $GITHUB_SHA to gh-pages"
git push origin +gh-pages
46 changes: 46 additions & 0 deletions ci/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3

MAPPING = {
"build-script.html": "https://doc.rust-lang.org/cargo/reference/build-scripts.html",
"config.html": None,
"crates-io.html": "https://doc.rust-lang.org/cargo/reference/publishing.html",
"environment-variables.html": None,
"external-tools.html": None,
"faq.html": "https://doc.rust-lang.org/cargo/faq.html",
"guide.html": "https://doc.rust-lang.org/cargo/guide/",
"index.html": "https://doc.rust-lang.org/cargo/",
"manifest.html": None,
"pkgid-spec.html": None,
"policies.html": "https://crates.io/policies",
"source-replacement.html": None,
"specifying-dependencies.html": None,
}

TEMPLATE = """\
<html>
<head>
<meta http-equiv="refresh" content="0; url={mapped}" />
<script>
window.location.replace("{mapped}" + window.location.hash);
</script>
<title>Page Moved</title>
</head>
<body>
This page has moved. Click <a href="{mapped}">here</a> to go to the new page.
</body>
</html>
"""

def main():
for name in sorted(MAPPING):
with open(name, 'w') as f:
mapped = MAPPING[name]
if mapped is None:
mapped = "https://doc.rust-lang.org/cargo/reference/{}".format(name)
f.write(TEMPLATE.format(name=name, mapped=mapped))

with open('CNAME', 'w') as f:
f.write('doc.crates.io')

if __name__ == '__main__':
main()