diff options
author | Jelmer Vernooij <jelmer@google.com> | 2017-03-20 23:29:37 +0000 |
---|---|---|
committer | Jelmer Vernooij <jelmer@jelmer.uk> | 2017-03-22 11:56:09 +0000 |
commit | 94e80f467a0554898cb72fb89cd85b5e43427b94 (patch) | |
tree | d8209366357683384898b1fb6983113cf151205e | |
parent | fd0ee00949c9aad3140d5d850864ae43fb9ea40a (diff) |
Set base href, for the benefit of rendered pages with relative links.
Fixes #177
-rw-r--r-- | klaus/templates/skeleton.html | 3 | ||||
-rw-r--r-- | klaus/views.py | 10 |
2 files changed, 12 insertions, 1 deletions
diff --git a/klaus/templates/skeleton.html b/klaus/templates/skeleton.html index 76d71df..1768733 100644 --- a/klaus/templates/skeleton.html +++ b/klaus/templates/skeleton.html @@ -4,6 +4,9 @@ <link rel=stylesheet href={{ url_for('static', filename='pygments.css') }}> <link rel=stylesheet href={{ url_for('static', filename='klaus.css') }}> <link rel=icon type="image/png" href="{{ url_for('static', filename='favicon.png') }}" /> +{% if base_href %} +<base href="{{ base_href }}"/> +{% endif %} <title>{% block title %}{% endblock %} - {{ SITE_NAME }}</title> <script src={{ url_for('static', filename='klaus.js') }}></script> diff --git a/klaus/views.py b/klaus/views.py index cff75ca..c0afc03 100644 --- a/klaus/views.py +++ b/klaus/views.py @@ -36,7 +36,7 @@ def repo_list(): sort_key = lambda repo: repo.name reverse = False repos = sorted(current_app.repos.values(), key=sort_key, reverse=reverse) - return render_template('repo_list.html', repos=repos) + return render_template('repo_list.html', repos=repos, base_href=None) def robots_txt(): @@ -102,6 +102,7 @@ class BaseRepoView(View): 'path': path, 'blob_or_tree': blob_or_tree, 'subpaths': list(subpaths(path)) if path else None, + 'base_href': None, } @@ -202,6 +203,13 @@ class IndexView(TreeViewMixin, BaseRepoView): def make_template_context(self, *args): super(IndexView, self).make_template_context(*args) + self.context['base_href'] = url_for( + 'blob', + repo=self.context['repo'].name, + rev=self.context['rev'], + path='' + ) + self.context['page'] = 0 history_length = 10 history = self.context['repo'].history( |