Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
Version switching user experience improvements (apache#13921)
Browse files Browse the repository at this point in the history
* fix version switching for anchors and search

* improved redirects

* fix bug for dev previews; remove hardcoded protocol
  • Loading branch information
aaronmarkham authored and Gordon Reid committed Jan 27, 2019
1 parent ccab255 commit 90e20ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
13 changes: 8 additions & 5 deletions docs/_static/js/docversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@
*/

/* Set the version of the website */
function setVersion(){
let doc = window.location.pathname.match(/^\/(api\/.*)$/) || window.location.pathname.match(/^\/versions\/[^*]+\/(api\/.*)$/);
function setVersion(anchor){
if (arguments.length==0) {
anchor = window.location.hash
};
let doc = window.location.pathname.match(/^\/versions\/[^\/]+\/([^*]+.*)$/);
if (doc) {
if (document.getElementById('dropdown-menu-position-anchor-version')) {
versionNav = $('#dropdown-menu-position-anchor-version a.main-nav-link');
$(versionNav).each( function( index, el ) {
currLink = $( el ).attr('href');
version = currLink.match(/\/versions\/([0-9.master]+)\//);
version = currLink.match(/\/versions\/([^\/]+)\//);
if (version) {
versionedDoc = '/versions/' + version[1] + '/' + doc[1] + (window.location.hash || '');
versionedDoc = '/versions/' + version[1] + '/' + doc[1] + (anchor || '') + (window.location.search || '');
$( el ).attr('href', versionedDoc);
}
});
Expand All @@ -40,5 +43,5 @@ $(document).ready(function () {
});

$('a.reference.internal').click(function(){
setVersion();
setVersion($(this).attr("href"));
});
4 changes: 2 additions & 2 deletions docs/_static/searchtools_custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ var Search = {
highlightstring + item[2]).html(item[1]));
} else {
// normal html builders
var baseURL = 'https://' + window.location.hostname + '/';
var baseURL = window.location.protocol + '//' + window.location.hostname + '/';
var urlHref = window.location.href;
let urlSplits = urlHref.split("/");
let versionString = '';
Expand Down Expand Up @@ -570,7 +570,7 @@ var Search = {
}
Search.title.text(_('Search Results'));
if (!resultCount)
Search.status.text(_('Your search did not match any documents. Please make sure that all words are spelled correctly and that you\'ve selected enough categories.'));
Search.status.text(_('Your search did not match any documents in this version of the documentation. You can use the dropdown selector in the navigation bar to try another version. Please make sure that all words are spelled correctly and that you\'ve selected enough categories.'));
else
Search.status.text(_('Search finished, found %s page(s) matching the search query.').replace('%s', resultCount));
Search.status.fadeIn(500);
Expand Down
10 changes: 3 additions & 7 deletions docs/build_version_doc/artifacts/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ RewriteRule ^get_started/why_mxnet.html$ %{ENV:default_version}/faq/why_mxnet.ht
RewriteRule ^get_started.*$ %{ENV:default_version}/install/ [R=301,L]
RewriteRule ^how_to.*$ %{ENV:default_version}/faq/ [R=301,L]
RewriteRule ^api/python/symbol.html$ %{ENV:default_version}/api/python/symbol/symbol.html [R=301,L]
RewriteRule ^community/index.html$ %{ENV:default_version}/community/contribute.html [R=301,L]
RewriteRule ^(?:versions\/[^\/]+\/)?community/index.html$ %{ENV:default_version}/community/contribute.html [R=301,L]

# Navigation bar redirects to latest info
RewriteRule ^versions\/[0-9.]+\/architecture/(.*)$ %{ENV:default_version}/architecture/$1 [R=301,L]
RewriteRule ^versions\/[0-9.]+\/community/(.*)$ %{ENV:default_version}/community/$1 [R=301,L]
RewriteRule ^versions\/[0-9.]+\/faq/(.*)$ %{ENV:default_version}/faq/$1 [R=301,L]
RewriteRule ^versions\/[0-9.]+\/gluon/(.*)$ %{ENV:default_version}/gluon/$1 [R=301,L]
RewriteRule ^versions\/[0-9.]+\/install/(.*)$ %{ENV:default_version}/install/$1 [R=301,L]
RewriteRule ^versions\/[0-9.]+\/tutorials/(.*)$ %{ENV:default_version}/tutorials/$1 [R=301,L]
RewriteCond %{ENV:default_version}#\/$1 !^([^#]+)#\1$
RewriteRule ^(versions\/[^\/]+)?(?:\/)?(faq|community|install|gluon|tutorials|architecture)(.*)?$ %{ENV:default_version}/$2$3 [R=301,L]

# Redirect navbar APIs that did not exist
RewriteRule ^versions/0.11.0/api/python/contrib/onnx.html %{ENV:default_version}/error/api.html [R=301,L]
Expand Down

0 comments on commit 90e20ea

Please sign in to comment.