Skip to content

Commit 1aec001

Browse files
committed
Fix single page application on github pages
1 parent 4c56baf commit 1aec001

File tree

5 files changed

+98
-11
lines changed

5 files changed

+98
-11
lines changed

Diff for: .nojekyll

Whitespace-only changes.

Diff for: 404.html

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Single Page Apps for GitHub Pages</title>
6+
<script type="text/javascript">
7+
// Single Page Apps for GitHub Pages
8+
// https://github.com/rafrex/spa-github-pages
9+
// Copyright (c) 2016 Rafael Pedicini, licensed under the MIT License
10+
// ----------------------------------------------------------------------
11+
// This script takes the current url and converts the path and query
12+
// string into just a query string, and then redirects the browser
13+
// to the new url with only a query string and hash fragment,
14+
// e.g. http://www.foo.tld/one/two?a=b&c=d#qwe, becomes
15+
// http://www.foo.tld/?p=/one/two&q=a=b~and~c=d#qwe
16+
// Note: this 404.html file must be at least 512 bytes for it to work
17+
// with Internet Explorer (it is currently > 512 bytes)
18+
19+
// If you're creating a Project Pages site and NOT using a custom domain,
20+
// then set segmentCount to 1 (enterprise users may need to set it to > 1).
21+
// This way the code will only replace the route part of the path, and not
22+
// the real directory in which the app resides, for example:
23+
// https://username.github.io/repo-name/one/two?a=b&c=d#qwe becomes
24+
// https://username.github.io/repo-name/?p=/one/two&q=a=b~and~c=d#qwe
25+
// Otherwise, leave segmentCount as 0.
26+
var segmentCount = 1;
27+
28+
var l = window.location;
29+
l.replace(
30+
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
31+
l.pathname.split('/').slice(0, 1 + segmentCount).join('/') + '/?p=/' +
32+
l.pathname.slice(1).split('/').slice(segmentCount).join('/').replace(/&/g, '~and~') +
33+
(l.search ? '&q=' + l.search.slice(1).replace(/&/g, '~and~') : '') +
34+
l.hash
35+
);
36+
37+
</script>
38+
</head>
39+
<body>
40+
</body>
41+
</html>

Diff for: generate-docs.sh

+20-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -x
33

44
# Machine-specific path, naturally
5-
protocol_repo_path="$HOME/code/pristine/devtools-protocol"
5+
protocol_repo_path="$HOME/Projects/devtools-protocol"
66
local_script_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
77

88
browser_protocol_path="$protocol_repo_path/json/browser_protocol.json"
@@ -20,7 +20,6 @@ fi
2020
cp $js_protocol_path $local_v8_protocol_path
2121
# merge and create all our data files
2222
node merge-protocol-files.js $browser_protocol_path $js_protocol_path > $local_tot_protocol_path
23-
node create-domain-files.js
2423
node create-search-index.js
2524

2625
# get the latest change
@@ -44,18 +43,29 @@ cat _versions/tot.html | sed -Ee "s/^(<code browser>)Date.*/\1$br_date_line/" >
4443
cat _versions/tot.html.new | sed -Ee "s/^(<code js>)Date.*/\1$js_date_line/" > _versions/tot.html
4544
rm -f _versions/tot.html.new
4645

47-
git checkout -b gh-pages
48-
sed -i -- 's/_site/#_site/g' .gitignore
46+
yarn run build
4947

50-
git commit --amend --all -m "Update build"
48+
cd ..
5149

52-
# Check out previous branch
53-
git checkout -
50+
git clone [email protected]:timvdlippe/devtools-protocol.git --single-branch devtools-temp
5451

55-
git push dtprotocol git push dtprotocol gh-pages:gh-pages
52+
cd devtools-temp
5653

57-
git branch -D gh-pages
54+
git checkout --orphan gh-pages
5855

59-
sed -i -- 's/#_site/_site/g' .gitignore
56+
# remove all content
57+
git rm -rf -q .
58+
59+
cp -R ../debugger-protocol-viewer/_site/{*,.nojekyll} ./
60+
61+
git add .
62+
63+
git commit -am 'seed gh-pages'
64+
65+
git push -u origin gh-pages --force
66+
67+
cd ..
68+
69+
rm -rf devtools-temp
6070

6171
set +x

Diff for: index.html

+33-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,38 @@
4343
}
4444
</style>
4545
</custom-style>
46+
47+
<!-- Start Single Page Apps for GitHub Pages -->
48+
<script type="text/javascript">
49+
// Single Page Apps for GitHub Pages
50+
// https://github.com/rafrex/spa-github-pages
51+
// Copyright (c) 2016 Rafael Pedicini, licensed under the MIT License
52+
// ----------------------------------------------------------------------
53+
// This script checks to see if a redirect is present in the query string
54+
// and converts it back into the correct url and adds it to the
55+
// browser's history using window.history.replaceState(...),
56+
// which won't cause the browser to attempt to load the new url.
57+
// When the single page app is loaded further down in this file,
58+
// the correct url will be waiting in the browser's history for
59+
// the single page app to route accordingly.
60+
(function(l) {
61+
if (l.search) {
62+
var q = {};
63+
l.search.slice(1).split('&').forEach(function(v) {
64+
var a = v.split('=');
65+
q[a[0]] = a.slice(1).join('=').replace(/~and~/g, '&');
66+
});
67+
if (q.p !== undefined) {
68+
window.history.replaceState(null, null,
69+
l.pathname.slice(0, -1) + (q.p || '') +
70+
(q.q ? ('?' + q.q) : '') +
71+
l.hash
72+
);
73+
}
74+
}
75+
}(window.location))
76+
</script>
77+
<!-- End Single Page Apps for GitHub Pages -->
4678
</head>
4779
<body unresolved class="fullbleed layout vertical">
4880
<iron-location id="location"></iron-location>
@@ -333,7 +365,7 @@ <h4 id="simultaneous">Does the protocol support multiple simultaneous clients?</
333365
for (const link of domainContainer.querySelectorAll('a')) {
334366
if (link.classList.contains(domain)) {
335367
link.style.display = 'flex';
336-
link.href = `/${domain}/${link.dataset.title}`;
368+
link.href = `${domain}/${link.dataset.title}`;
337369
} else {
338370
link.style.display = 'none';
339371
}

Diff for: polymer.json

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"styles/**/*"
77
],
88
"extraDependencies": [
9+
"404.html",
10+
".nojekyll",
11+
"_data/**/*",
12+
"_versions/**/*",
913
"search_index/**/*",
1014
"bower_components/webcomponentsjs/*.js"
1115
],

0 commit comments

Comments
 (0)