Skip to content

Commit 2e5b680

Browse files
committed
Auto merge of #13414 - Alexendoo:generate-versions-html, r=
Generate versions HTML directly Generates the page at https://rust-lang.github.io/rust-clippy/ directly rather than creating a JSON file to load Also fixes #13413 r? `@flip1995` changelog: none
2 parents fdc1678 + d2305ff commit 2e5b680

File tree

3 files changed

+87
-84
lines changed

3 files changed

+87
-84
lines changed

.github/deploy.sh

+3-6
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ if [[ $BETA = "true" ]]; then
2525
fi
2626

2727
# Generate version index that is shown as root index page
28-
cp util/gh-pages/versions.html out/index.html
29-
30-
echo "Making the versions.json file"
31-
python3 ./util/versions.py out
28+
python3 ./util/versions.py ./util/gh-pages/versions.html out
3229

3330
# Now let's go have some fun with the cloned repo
3431
cd out
3532
git config user.name "GHA CI"
3633
git config user.email "[email protected]"
3734

35+
git status
36+
3837
if [[ -n $TAG_NAME ]]; then
3938
# track files, so that the following check works
4039
git add --intent-to-add "$TAG_NAME"
@@ -46,8 +45,6 @@ if [[ -n $TAG_NAME ]]; then
4645
git add "$TAG_NAME"
4746
# Update the symlink
4847
git add stable
49-
# Update versions file
50-
git add versions.json
5148
git commit -m "Add documentation for ${TAG_NAME} release: ${SHA}"
5249
elif [[ $BETA = "true" ]]; then
5350
if git diff --exit-code --quiet -- beta/; then

util/gh-pages/versions.html

+63-58
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<!DOCTYPE html>
2+
<!-- Expanded by util/versions.py into the HTML file seen at https://rust-lang.github.io/rust-clippy/ -->
23
<html lang="en">
34
<head>
45
<meta charset="UTF-8"/>
@@ -7,82 +8,86 @@
78
<title>Clippy lints documentation</title>
89

910
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css"/>
10-
<style>
11-
[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak { display: none !important; }
12-
</style>
1311
</head>
1412
<body>
15-
<div class="container" ng-app="clippy" ng-controller="docVersions">
13+
<div class="container">
1614
<div class="page-header">
1715
<h1>Clippy lints documentation</h1>
1816
</div>
1917

20-
<div ng-cloak>
21-
<div class="alert alert-info" role="alert" ng-if="loading">
22-
Loading&#x2026;
23-
</div>
24-
<div class="alert alert-danger" role="alert" ng-if="error">
25-
Error loading versions!<br/>
26-
You can always try to get <a href="master/index.html">the master branch docs</a>.
27-
</div>
28-
29-
<article class="panel panel-default" ng-show="data">
18+
<div>
19+
<article class="panel panel-default">
3020
<div class="panel-heading">
3121
<h3 class="panel-title">
3222
Available versions
3323
</h3>
3424
</div>
3525

3626
<ul class="list-group">
37-
<a class="list-group-item" ng-repeat="version in data | orderBy:versionOrder:true"
38-
href="./{{version}}/index.html">
39-
{{version}}
40-
</a>
27+
$list
4128
</ul>
4229
</article>
4330
</div>
4431
</div>
4532

46-
<a href="https://github.com/rust-lang/rust-clippy">
47-
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"/>
48-
</a>
49-
50-
51-
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.12/angular.min.js"></script>
52-
<script>
53-
angular.module('clippy', [])
54-
.controller('docVersions', function ($scope, $http) {
55-
$scope.loading = true;
56-
57-
$scope.normalizeVersion = function(v) {
58-
return v.replace(/^rust-/, '');
59-
};
60-
61-
$scope.versionOrder = function(v) {
62-
if (v === 'master') { return Infinity; }
63-
if (v === 'stable') { return Number.MAX_VALUE; }
64-
if (v === 'beta') { return Number.MAX_VALUE - 1; }
65-
if (v === 'pre-1.29.0') { return Number.MIN_VALUE; }
66-
67-
return $scope.normalizeVersion(v)
68-
.split('.')
69-
.reverse()
70-
.reduce(function(acc, val, index) {
71-
return acc + (val * Math.pow(100, index));
72-
}, 0);
33+
<a
34+
aria-label="View source on GitHub"
35+
class="github-corner"
36+
href="https://github.com/rust-lang/rust-clippy"
37+
rel="noopener noreferrer"
38+
target="_blank"
39+
>
40+
<svg
41+
width="80"
42+
height="80"
43+
viewBox="0 0 250 250"
44+
style="position: absolute; top: 0; border: 0; right: 0"
45+
aria-hidden="true"
46+
>
47+
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z" fill="var(--theme-color)"></path>
48+
<path
49+
d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
50+
fill="currentColor"
51+
style="transform-origin: 130px 106px"
52+
class="octo-arm"
53+
></path>
54+
<path
55+
d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
56+
fill="currentColor"
57+
class="octo-body"
58+
></path>
59+
</svg>
60+
<style>
61+
.github-corner svg {
62+
fill: black;
63+
color: white;
7364
}
74-
75-
$http.get('./versions.json')
76-
.success(function (data) {
77-
$scope.data = data;
78-
$scope.loading = false;
79-
})
80-
.error(function (data) {
81-
$scope.error = data;
82-
$scope.loading = false;
83-
});
84-
})
85-
;
86-
</script>
65+
.github-corner:hover .octo-arm {
66+
animation: octocat-wave 560ms ease-in-out;
67+
}
68+
@keyframes octocat-wave {
69+
0%,
70+
100% {
71+
transform: rotate(0);
72+
}
73+
20%,
74+
60% {
75+
transform: rotate(-25deg);
76+
}
77+
40%,
78+
80% {
79+
transform: rotate(10deg);
80+
}
81+
}
82+
@media (max-width: 500px) {
83+
.github-corner:hover .octo-arm {
84+
animation: none;
85+
}
86+
.github-corner .octo-arm {
87+
animation: octocat-wave 560ms ease-in-out;
88+
}
89+
}
90+
</style>
91+
</a>
8792
</body>
8893
</html>

util/versions.py

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
#!/usr/bin/env python
22

3+
from string import Template
4+
import argparse
35
import json
4-
import logging as log
56
import os
67
import sys
78

8-
log.basicConfig(level=log.INFO, format="%(levelname)s: %(message)s")
9-
10-
119
def key(v):
1210
if v == "master":
13-
return float("inf")
14-
if v == "stable":
1511
return sys.maxsize
16-
if v == "beta":
12+
if v == "stable":
1713
return sys.maxsize - 1
14+
if v == "beta":
15+
return sys.maxsize - 2
1816
if v == "pre-1.29.0":
1917
return -1
18+
if not v.startswith("rust-"):
19+
return None
2020

2121
v = v.replace("rust-", "")
2222

@@ -26,26 +26,27 @@ def key(v):
2626

2727
return s
2828

29-
3029
def main():
31-
if len(sys.argv) < 2:
32-
log.error("specify output directory")
33-
return
30+
parser = argparse.ArgumentParser()
31+
parser.add_argument("input", help="path to the versions.html template", type=argparse.FileType("r"))
32+
parser.add_argument("outdir", help="path to write the output HTML")
33+
args = parser.parse_args()
3434

35-
outdir = sys.argv[1]
3635
versions = [
3736
dir
38-
for dir in os.listdir(outdir)
39-
if not dir.startswith(".")
40-
and not dir.startswith("v")
41-
and os.path.isdir(os.path.join(outdir, dir))
37+
for dir in os.listdir(args.outdir)
38+
if key(dir) is not None
4239
]
43-
versions.sort(key=key)
40+
versions.sort(key=key, reverse=True)
41+
links = [f'<a class="list-group-item" href="./{version}/index.html">{version}</a>' for version in versions]
4442

45-
with open(os.path.join(outdir, "versions.json"), "w") as fp:
46-
json.dump(versions, fp, indent=2)
47-
log.info("wrote JSON for great justice")
43+
template = Template(args.input.read())
44+
html = template.substitute(list="\n".join(links))
4845

46+
path = os.path.join(args.outdir, "index.html")
47+
with open(path, "w") as out:
48+
out.write(html)
49+
print(f"wrote HTML to {path}")
4950

5051
if __name__ == "__main__":
5152
main()

0 commit comments

Comments
 (0)