From 208922f1fc480bc7160700b34a01f3be0ef4685b Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Wed, 18 Oct 2023 12:08:28 -0400 Subject: [PATCH 1/2] ci: pull out generate.py from gh-pages branch --- ci/generate.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 ci/generate.py diff --git a/ci/generate.py b/ci/generate.py new file mode 100644 index 00000000000..70a7dc1e68d --- /dev/null +++ b/ci/generate.py @@ -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 = """\ + + + + +Page Moved + + +This page has moved. Click here to go to the new page. + + +""" + +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() From 4f0016d457c98dc4d9e6cada461c63a6b1ca6996 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Wed, 18 Oct 2023 12:13:38 -0400 Subject: [PATCH 2/2] ci: generate link redirections when publising contrib doc --- .github/workflows/contrib.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/contrib.yml b/.github/workflows/contrib.yml index 1e95316e505..6ab60f96c61 100644 --- a/.github/workflows/contrib.yml +++ b/.github/workflows/contrib.yml @@ -27,8 +27,11 @@ 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" @@ -36,5 +39,11 @@ jobs: 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