From a1c835bf4647cf2cb13759631079f606ae4f49ea Mon Sep 17 00:00:00 2001 From: Deimos Date: Sat, 10 Aug 2019 14:38:17 -0600 Subject: [PATCH] Show "breadcrumbs" on wiki pages --- tildes/scss/modules/_breadcrumbs.scss | 14 ++++++++++++++ tildes/scss/styles.scss | 1 + tildes/tildes/models/group/group_wiki_page.py | 17 +++++++++++++++-- tildes/tildes/templates/base.jinja2 | 2 ++ tildes/tildes/templates/group_wiki_page.jinja2 | 13 +++++++++++++ 5 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 tildes/scss/modules/_breadcrumbs.scss diff --git a/tildes/scss/modules/_breadcrumbs.scss b/tildes/scss/modules/_breadcrumbs.scss new file mode 100644 index 0000000..af36092 --- /dev/null +++ b/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; + } + } +} diff --git a/tildes/scss/styles.scss b/tildes/scss/styles.scss index da31d4d..538302e 100644 --- a/tildes/scss/styles.scss +++ b/tildes/scss/styles.scss @@ -9,6 +9,7 @@ @import "base"; @import "layout"; +@import "modules/breadcrumbs"; @import "modules/btn"; @import "modules/chip"; @import "modules/comment"; diff --git a/tildes/tildes/models/group/group_wiki_page.py b/tildes/tildes/models/group/group_wiki_page.py index a44d7c4..c251337 100644 --- a/tildes/tildes/models/group/group_wiki_page.py +++ b/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.""" diff --git a/tildes/tildes/templates/base.jinja2 b/tildes/tildes/templates/base.jinja2 index 51bef86..92b1e91 100644 --- a/tildes/tildes/templates/base.jinja2 +++ b/tildes/tildes/templates/base.jinja2 @@ -84,6 +84,8 @@
+{% block pre_main_heading %}{% endblock %} + {# Only output the

tag if the main_heading block has some content #} {% set main_heading %}{% block main_heading %}{% endblock %}{% endset %} {% if main_heading %} diff --git a/tildes/tildes/templates/group_wiki_page.jinja2 b/tildes/tildes/templates/group_wiki_page.jinja2 index e116864..e29afa2 100644 --- a/tildes/tildes/templates/group_wiki_page.jinja2 +++ b/tildes/tildes/templates/group_wiki_page.jinja2 @@ -13,6 +13,19 @@ {% block main_classes %}text-formatted text-wiki{% endblock %} +{% block pre_main_heading %} + +{% endblock %} + {% block main_heading %}{{ page.page_name }}{% endblock %} {% block content %}