mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
fixed broken links in main/sidemenu when using server_dir '/'
This commit is contained in:
parent
d4d6948eb9
commit
32872cea12
2
cfg.py
2
cfg.py
@ -19,7 +19,7 @@ host = None
|
||||
port = None
|
||||
debug = False
|
||||
no_daemon = False
|
||||
server_dir = ''
|
||||
server_dir = '/'
|
||||
|
||||
main_menu = Menu()
|
||||
|
||||
|
||||
6
menu.py
6
menu.py
@ -1,4 +1,5 @@
|
||||
from urlparse import urlparse
|
||||
import util
|
||||
import cfg
|
||||
|
||||
|
||||
@ -31,7 +32,7 @@ class Menu(object):
|
||||
def find(self, url, basehref=True):
|
||||
"""Return a menu item with given URL"""
|
||||
if basehref and url.startswith('/'):
|
||||
url = cfg.server_dir + url
|
||||
url = util.rel_urljoin([cfg.server_dir, url])
|
||||
|
||||
for item in self.items:
|
||||
if item.url == url:
|
||||
@ -51,7 +52,8 @@ class Menu(object):
|
||||
cfg.server_dir to it"""
|
||||
|
||||
if basehref and url.startswith("/"):
|
||||
url = cfg.server_dir + url
|
||||
url = util.rel_urljoin([cfg.server_dir, url])
|
||||
#url = cfg.server_dir + url
|
||||
|
||||
item = Menu(label=label, icon=icon, url=url, order=order)
|
||||
self.items.append(item)
|
||||
|
||||
@ -59,11 +59,11 @@
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a href="{{ basehref }}/" class="logo-top">
|
||||
<a href="{{ basehref }}" class="logo-top">
|
||||
<img src="{% static 'theme/img/freedombox-logo-32px.png' %}"
|
||||
alt="FreedomBox" />
|
||||
</a>
|
||||
<a class="brand" href="{{ basehref }}/">FreedomBox</a>
|
||||
<a class="brand" href="{{ basehref }}">FreedomBox</a>
|
||||
{% block add_nav_and_login %}
|
||||
<div class="nav-collapse">
|
||||
<ul class="nav">
|
||||
|
||||
11
util.py
11
util.py
@ -12,17 +12,20 @@ class PlinthRedirect(HttpResponseRedirect):
|
||||
"""
|
||||
def __init__(self, redirect_to, *args, **kwargs):
|
||||
if not redirect_to.startswith(cfg.server_dir):
|
||||
redirect_to = urljoin([cfg.server_dir, redirect_to])
|
||||
redirect_to = rel_urljoin([cfg.server_dir, redirect_to])
|
||||
return super(PlinthRedirect, self).__init__(redirect_to,
|
||||
*args, **kwargs)
|
||||
|
||||
|
||||
def urljoin(parts):
|
||||
def rel_urljoin(parts, prepend_slash=True):
|
||||
"""
|
||||
urllibs' urljoin joins ("foo", "/bar") to "/bar".
|
||||
Instead, just concatenate the parts with "/" to i.e. /foo/bar
|
||||
Instead concatenate the parts with "/" to i.e. /foo/bar
|
||||
"""
|
||||
return '/' + '/'.join(s.strip('/') for s in parts)
|
||||
url = '/'.join(s.strip('/') for s in parts)
|
||||
if prepend_slash and not url.startswith('/'):
|
||||
url = '/' + url
|
||||
return url
|
||||
|
||||
|
||||
def mkdir(newdir):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user