Skip to content

Commit

Permalink
Add trailing slash when redirecting to directories; resolves #46
Browse files Browse the repository at this point in the history
  • Loading branch information
jimporter committed Mar 16, 2021
1 parent ba544cd commit 79827d4
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mike/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def set_default(version, template=None, *, branch='gh-pages', message=None,
t = _redirect_template(template)
with git_utils.Commit(branch, message) as commit:
commit.add_file(git_utils.FileInfo(
os.path.join(prefix, 'index.html'), t.render(href=version)
os.path.join(prefix, 'index.html'), t.render(href=version + '/')
))


Expand Down
2 changes: 1 addition & 1 deletion mike/themes/mkdocs/js/version-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ window.addEventListener("DOMContentLoaded", function() {
return {text: i.title, value: i.version};
}), realVersion);
select.addEventListener("change", function(event) {
window.location.href = REL_BASE_URL + "/../" + this.value;
window.location.href = REL_BASE_URL + "/../" + this.value + "/";
});

var container = document.createElement("div");
Expand Down
2 changes: 1 addition & 1 deletion mike/themes/readthedocs/js/version-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ window.addEventListener("DOMContentLoaded", function() {
}), realVersion);
select.id = "version-selector";
select.addEventListener("change", function(event) {
window.location.href = REL_BASE_URL + "/../" + this.value;
window.location.href = REL_BASE_URL + "/../" + this.value + "/";
});

var title = document.querySelector("div.wy-side-nav-search");
Expand Down
4 changes: 2 additions & 2 deletions test/integration/test_set_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def _deploy(self, branch=None, versions=['1.0'], prefix=''):
for i in versions:
assertPopen(['mike', 'deploy', i] + extra_args)

def _test_default(self, expr=r'window\.location\.replace\("1\.0"\)',
def _test_default(self, expr=r'window\.location\.replace\("1\.0/"\)',
expected_message=None, directory='.'):
message = assertPopen(['git', 'log', '-1', '--pretty=%B']).rstrip()
if expected_message:
Expand Down Expand Up @@ -48,7 +48,7 @@ def test_custom_template(self):
assertPopen(['mike', 'set-default', '1.0', '-T',
os.path.join(test_data_dir, 'template.html')])
check_call_silent(['git', 'checkout', 'gh-pages'])
self._test_default(r'^Redirecting to 1\.0$')
self._test_default(r'^Redirecting to 1\.0/$')

def test_from_subdir(self):
self._deploy()
Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def setUp(self):
def _deploy(self, branch='gh-pages', prefix=''):
commands.deploy(self.stage, '1.0', branch=branch, prefix=prefix)

def _test_default(self, expr=r'window\.location\.replace\("1\.0"\)',
def _test_default(self, expr=r'window\.location\.replace\("1\.0/"\)',
expected_message=None, directory='.'):
message = check_output(['git', 'log', '-1', '--pretty=%B']).rstrip()
if expected_message:
Expand All @@ -422,7 +422,7 @@ def test_custom_template(self):
mock.mock_open(read_data=b'{{href}}')):
commands.set_default('1.0', 'template.html')
check_call_silent(['git', 'checkout', 'gh-pages'])
self._test_default(r'^1\.0$')
self._test_default(r'^1\.0/$')

def test_branch(self):
self._deploy('branch')
Expand Down

0 comments on commit 79827d4

Please sign in to comment.