Browse Source

Show "breadcrumbs" on wiki pages

merge-requests/76/merge
Deimos 5 years ago
parent
commit
a1c835bf46
  1. 14
      tildes/scss/modules/_breadcrumbs.scss
  2. 1
      tildes/scss/styles.scss
  3. 17
      tildes/tildes/models/group/group_wiki_page.py
  4. 2
      tildes/tildes/templates/base.jinja2
  5. 13
      tildes/tildes/templates/group_wiki_page.jinja2

14
tildes/scss/modules/_breadcrumbs.scss

@ -0,0 +1,14 @@
ol.breadcrumb,
ul.breadcrumb {
margin-left: 0;
font-size: 0.6rem;
line-height: 0.8rem;
a {
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
}

1
tildes/scss/styles.scss

@ -9,6 +9,7 @@
@import "base";
@import "layout";
@import "modules/breadcrumbs";
@import "modules/btn";
@import "modules/chip";
@import "modules/comment";

17
tildes/tildes/models/group/group_wiki_page.py

@ -4,8 +4,8 @@
"""Contains the GroupWikiPage class."""
from datetime import datetime
from pathlib import Path
from typing import Any, Optional, Sequence, Tuple
from pathlib import Path, PurePath
from typing import Any, List, Optional, Sequence, Tuple
from pygit2 import Repository, Signature
from pyramid.security import Allow, DENY_ALL, Everyone
@ -104,6 +104,19 @@ class GroupWikiPage(DatabaseModel):
"""Return the page's slug, which is also its filename with no extension."""
return self.file_path.stem
@property
def folders(self) -> List[PurePath]:
"""Return a list of the folders the page is inside (if any)."""
path = PurePath(self.path)
# the last element of .parents will be ".", chop that off
folders = list(path.parents)[:-1]
# reverse the list, since .parents goes "upwards" towards root
folders.reverse()
return folders
@property
def history_url(self) -> str:
"""Return a url to the page's edit history."""

2
tildes/tildes/templates/base.jinja2

@ -84,6 +84,8 @@
<main class="{% block main_classes %}{% endblock %}" data-js-hide-sidebar-if-open>
{% block pre_main_heading %}{% endblock %}
{# Only output the <h1> tag if the main_heading block has some content #}
{% set main_heading %}{% block main_heading %}{% endblock %}{% endset %}
{% if main_heading %}

13
tildes/tildes/templates/group_wiki_page.jinja2

@ -13,6 +13,19 @@
{% block main_classes %}text-formatted text-wiki{% endblock %}
{% block pre_main_heading %}
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="{{ request.route_url("group_wiki", group_path=page.group.path) }}">~{{ page.group.path }} wiki</a>
</li>
{% for folder in page.folders %}
<li class="breadcrumb-item">
<a href="{{ request.route_url("group_wiki_page", group_path=page.group.path, wiki_page_path=folder|string) }}">{{ folder.name }}</a>
</li>
{% endfor %}
</ol>
{% endblock %}
{% block main_heading %}{{ page.page_name }}{% endblock %}
{% block content %}

Loading…
Cancel
Save