# Normalise links
return os.path.normpath(path)
+ def _make_url(self, path):
+ """
+ Composes the URL out of the path
+ """
+ # Remove any leading slashes (if present)
+ path = path.removeprefix("/")
+
+ return os.path.join("/docs", path)
+
def page_exists(self, path):
page = self.get_page(path)
# Just creates a blank last version of the page
self.create_page(page, author=author, content=None, **kwargs)
- def make_breadcrumbs(self, url):
- # Split and strip all empty elements (double slashes)
- parts = list(e for e in url.split("/") if e)
-
+ def make_breadcrumbs(self, path):
ret = []
- for part in ("/".join(parts[:i]) for i in range(1, len(parts))):
- ret.append(("/docs/%s" % part, self.get_page_title(part, os.path.basename(part))))
- return ret
+ while path:
+ # Cut off everything after the last slash
+ path, _, _ = path.rpartition("/")
+
+ # Do not include the root
+ if not path:
+ break
+
+ # Find the page
+ page = self.get_page(path)
+
+ # Append the URL and title to the output
+ ret.append((
+ page.url if page else self._make_url(path),
+ page.title if page else os.path.basename(path),
+ ))
+
+ # Return the breadcrumbs in order
+ return reversed(ret)
def search(self, query, account=None, limit=None):
res = self._get_pages("""
@property
def url(self):
- return "/docs%s" % self.page
+ return self.backend.wiki._make_url(self.page)
@property
def full_url(self):