Skip to content

Commit 0820fa1

Browse files
committed
Auto merge of #12846 - rust-lang:revert-12834-pr/contrib, r=epage
docs(contrib): generate redirection HTML pages in CI ### What does this PR try to resolve? #12834 wiped out the old content of all link redirections. From my understanding it relies on the existing gh-pages hosting those files. This PR pulls out the [`generate.py`](https://github.com/rust-lang/cargo/blob/cff41259837c912b44f2eba98777d71996740fe0/generate.py) from older `gh-pages` branch, and run it during the CI deploy job. ### How to review It succeeds on my fork <https://github.com/weihanglo/cargo/tree/gh-pages> ([CI log](https://github.com/weihanglo/cargo/actions/runs/6564128361/job/17829881499#step:4:1)). I don't think `.lock` or [`.nojekyll`](https://github.blog/2009-12-29-bypassing-jekyll-on-github-pages/) is needed. If it causes problem, we can add them back.
2 parents 9b99415 + 4f0016d commit 0820fa1

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

Diff for: .github/workflows/contrib.yml

+9
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,23 @@ jobs:
2727
echo `pwd`/mdbook >> $GITHUB_PATH
2828
- name: Deploy docs
2929
run: |
30+
GENERATE_PY="$(pwd)/ci/generate.py"
31+
3032
cd src/doc/contrib
3133
mdbook build
34+
3235
# Override previous ref to avoid keeping history.
3336
git worktree add --orphan -B gh-pages gh-pages
3437
git config user.name "Deploy from CI"
3538
git config user.email ""
3639
cd gh-pages
3740
mv ../book contrib
3841
git add contrib
42+
43+
# Generate HTML for link redirections.
44+
python3 "$GENERATE_PY"
45+
git add *.html
46+
git add CNAME
47+
3948
git commit -m "Deploy $GITHUB_SHA to gh-pages"
4049
git push origin +gh-pages

Diff for: ci/generate.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
3+
MAPPING = {
4+
"build-script.html": "https://doc.rust-lang.org/cargo/reference/build-scripts.html",
5+
"config.html": None,
6+
"crates-io.html": "https://doc.rust-lang.org/cargo/reference/publishing.html",
7+
"environment-variables.html": None,
8+
"external-tools.html": None,
9+
"faq.html": "https://doc.rust-lang.org/cargo/faq.html",
10+
"guide.html": "https://doc.rust-lang.org/cargo/guide/",
11+
"index.html": "https://doc.rust-lang.org/cargo/",
12+
"manifest.html": None,
13+
"pkgid-spec.html": None,
14+
"policies.html": "https://crates.io/policies",
15+
"source-replacement.html": None,
16+
"specifying-dependencies.html": None,
17+
}
18+
19+
TEMPLATE = """\
20+
<html>
21+
<head>
22+
<meta http-equiv="refresh" content="0; url={mapped}" />
23+
<script>
24+
window.location.replace("{mapped}" + window.location.hash);
25+
</script>
26+
<title>Page Moved</title>
27+
</head>
28+
<body>
29+
This page has moved. Click <a href="{mapped}">here</a> to go to the new page.
30+
</body>
31+
</html>
32+
"""
33+
34+
def main():
35+
for name in sorted(MAPPING):
36+
with open(name, 'w') as f:
37+
mapped = MAPPING[name]
38+
if mapped is None:
39+
mapped = "https://doc.rust-lang.org/cargo/reference/{}".format(name)
40+
f.write(TEMPLATE.format(name=name, mapped=mapped))
41+
42+
with open('CNAME', 'w') as f:
43+
f.write('doc.crates.io')
44+
45+
if __name__ == '__main__':
46+
main()

0 commit comments

Comments
 (0)