Skip to content

Commit ca892fd

Browse files
committed
add version drop down to docs website
1 parent 62c8514 commit ca892fd

File tree

7 files changed

+71
-20
lines changed

7 files changed

+71
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"scripts": {
1313
"build": "scripts/build.sh",
1414
"watch": "babel ./modules --watch -d lib",
15-
"build-website": "babel-node website/scripts/build.js > website/index.html",
15+
"build-website": "scripts/build-website.sh",
1616
"examples": "webpack-dev-server --config examples/webpack.config.js --content-base examples --inline",
1717
"prepublish": "npm run build",
1818
"test": "jsxhint modules && karma start"

website/scripts/build.js renamed to scripts/build-website-tag.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ marked.setOptions({
1515
});
1616

1717
getCategories().then((categories) => {
18+
var versions = process.argv[2].split('\n');
1819
var html = React.renderToStaticMarkup(
19-
React.createElement(Page, { categories })
20+
React.createElement(Page, { categories, versions })
2021
);
2122
console.log('<!doctype html>'+html);
2223
});
@@ -63,14 +64,14 @@ class Page extends React.Component {
6364
<head>
6465
<meta charSet="utf-8"/>
6566
<title>React Router Documentation</title>
66-
<link rel="stylesheet" href="./styles.css"/>
67-
<link rel="stylesheet" href="./syntax.css"/>
67+
<link rel="stylesheet" href="/styles.css"/>
68+
<link rel="stylesheet" href="/syntax.css"/>
6869
</head>
6970
<body>
7071
<main className="Main">
7172
<div className="Main__Content">
7273
<center>
73-
<img src="./img/vertical.png" width="367" style={{marginBottom: 40}}/>
74+
<img src="/img/vertical.png" width="367" style={{marginBottom: 40}}/>
7475
</center>
7576
<p>
7677
React Router is a complete routing solution designed specifically
@@ -100,8 +101,14 @@ class Page extends React.Component {
100101
</div>
101102
</main>
102103
<nav className="Nav">
103-
<img src="./img/horizontal.png" width="100%"/>
104-
<br/>
104+
<img src="/img/horizontal.png" width="100%"/>
105+
<p>
106+
version: <select id="version">
107+
{this.props.versions.map((version) => (
108+
<option>{version}</option>
109+
))}
110+
</select>
111+
</p>
105112
{this.props.categories.map((category) => (
106113
<div className="Category">
107114
<div className="Category__Name">{category.name}</div>
@@ -117,7 +124,7 @@ class Page extends React.Component {
117124
</div>
118125
))}
119126
</nav>
120-
<script src="app.js"></script>
127+
<script src="/app.js"></script>
121128
</body>
122129
</html>
123130
);

scripts/build-website.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash -e
2+
branch=$(git branch | sed -n "/\* /s///p")
3+
rm -rf tmp
4+
mkdir tmp
5+
cp -R website tmp/website
6+
cp -R scripts tmp/scripts
7+
8+
versions="$(cat website/config)"
9+
10+
count=0
11+
while read line
12+
do
13+
if [ ! -f tmp/website/tags/$line.html ]; then
14+
git checkout "$line"
15+
./node_modules/.bin/babel-node ./tmp/scripts/build-website-tag.js "$versions" > tmp/website/tags/$line.html
16+
fi
17+
18+
if [ "$count" -eq 0 ]; then
19+
cp tmp/website/tags/$line.html tmp/website/index.html
20+
fi
21+
22+
((count++))
23+
done < website/config
24+
25+
git checkout $branch
26+
rm -rf website
27+
mv tmp/website website
28+
rm -rf tmp
29+

scripts/publish-docs.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
npm run build-website
2+
cd website
3+
rm -rf .git
4+
git init .
5+
git remote add origin [email protected]:rackt/react-router.git
6+
git checkout -b gh-pages
7+
git add .
8+
git commit -m 'publishing docs'
9+
git push origin gh-pages -f
10+
rm -rf .git
11+
cd ..
12+

scripts/release.sh

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,5 @@ git push origin latest -f
4141
npm publish build
4242

4343
echo "# Publishing docs website"
44-
npm run build-website
45-
cd website
46-
rm -rf .git
47-
git init .
48-
git remote add origin [email protected]:rackt/react-router.git
49-
git checkout -b gh-pages
50-
git add .
51-
git commit -m 'publishing docs'
52-
git push origin gh-pages -f
53-
rm -rf .git
54-
cd ..
44+
./publish-docs.sh
5545

website/app.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
// need to fix the marked output of these things, for some reason they are wrapped
22
// in `pre > code > div.highlight > pre
3-
[].slice.call(document.getElementsByClassName('highlight')).forEach(function (el) {
3+
[].slice.call(document.getElementsByClassName('highlight')).forEach(function(el) {
44
var stupidPre = el.parentNode.parentNode;
55
var parent = stupidPre.parentNode;
66
parent.insertBefore(el, stupidPre);
77
parent.removeChild(stupidPre);
88
});
99

10+
var version = document.getElementById('version');
11+
12+
var segments = document.location.pathname.split('/');
13+
if (segments.indexOf('tags') !== -1)
14+
version.value = segments[2].replace(/\.html$/, '');
15+
16+
version.addEventListener('change', function() {
17+
document.location = '/tags/'+this.value+'.html';
18+
}, false);
19+

website/config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
v0.13.3
2+
v1.0.0-beta1
3+

0 commit comments

Comments
 (0)