From: Michael Tremer Date: Tue, 27 Jun 2023 08:51:29 +0000 (+0000) Subject: docs: Refactor showing pages X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cf59466c4e7eb85ec67a8609bb955fd6a85c451d;p=ipfire.org.git docs: Refactor showing pages Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 44271451..8277a706 100644 --- a/Makefile.am +++ b/Makefile.am @@ -189,6 +189,17 @@ templates_donate_messages_DATA = \ templates_donate_messagesdir = $(templates_donatedir)/messages +templates_docs_DATA = \ + src/templates/docs/base.html \ + src/templates/docs/page.html + +templates_docsdir = $(templatesdir)/docs + +templates_docs_modules_DATA = \ + src/templates/docs/modules/header.html + +templates_docs_modulesdir = $(templates_docsdir)/modules + templates_downloads_DATA = \ src/templates/downloads/mirrors.html \ src/templates/downloads/release.html \ @@ -315,12 +326,10 @@ templates_users_modulesdir = $(templates_usersdir)/modules templates_wiki_DATA = \ src/templates/wiki/404.html \ - src/templates/wiki/base.html \ src/templates/wiki/confirm-delete.html \ src/templates/wiki/confirm-restore.html \ src/templates/wiki/diff.html \ src/templates/wiki/edit.html \ - src/templates/wiki/page.html \ src/templates/wiki/recent-changes.html \ src/templates/wiki/revisions.html \ src/templates/wiki/search-results.html \ @@ -342,8 +351,7 @@ templates_wiki_messagesdir = $(templates_wikidir)/messages templates_wiki_modules_DATA = \ src/templates/wiki/modules/diff.html \ - src/templates/wiki/modules/list.html \ - src/templates/wiki/modules/navbar.html + src/templates/wiki/modules/list.html templates_wiki_modulesdir = $(templates_wikidir)/modules diff --git a/src/templates/docs/base.html b/src/templates/docs/base.html index b3acb4b5..f151cbe1 100644 --- a/src/templates/docs/base.html +++ b/src/templates/docs/base.html @@ -1,7 +1,7 @@ {% extends "../base.html" %} -{% block content %} - {% module WikiNavbar() %} +{% block container %} + {% module DocsHeader() %} {% block main %}{% end block %} {% end block %} diff --git a/src/templates/docs/modules/header.html b/src/templates/docs/modules/header.html index c8c1c3f3..10114f4a 100644 --- a/src/templates/docs/modules/header.html +++ b/src/templates/docs/modules/header.html @@ -1,17 +1,43 @@ -{% if len(breadcrumbs) >= 1 %} - -{% end %} + {% for p, title in breadcrumbs %} +
  • + {{ title }} +
  • + {% end %} + + {% if page_title %} +
  • + + {{ page_title }} + +
  • + {% end %} + + {% if suffix %} +
  • + {{ suffix }} +
  • + {% end %} + + + +

    {{ page_title or _("IPFire Docs") }}

    + + + diff --git a/src/templates/docs/page.html b/src/templates/docs/page.html index 9edd2538..5ada046b 100644 --- a/src/templates/docs/page.html +++ b/src/templates/docs/page.html @@ -30,42 +30,61 @@ {% block main %} {% import os.path %} -
    -
    - {% raw page.html %} +
    +
    +
    + {% raw page.html %} +
    -
    + - +
    +
    + -

    - {% if current_user %} - {% if page.is_watched_by(current_user) %} - - {% else %} - - {% end %} • - {% end %} +

    +
    +
    + {% if current_user %} + {% if page.is_watched_by(current_user) %} + + + + {% else %} + + + + {% end %} + {% end %} - - {{ _("Older Revisions") }} - + + {{ _("Older Revisions") }} + - • +
    + {{ locale.format_date(page.timestamp) }} +
    - {{ locale.format_date(page.timestamp) }} - - {% if page.author %} - • - - - {{ page.author }} - - {% end %} -

    + {% if page.author %} + + {{ page.author }} + + {% end %} +
    +
    +
    +
    +
    {% end block %} diff --git a/src/web/__init__.py b/src/web/__init__.py index 633d923e..5e95bc93 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -70,6 +70,9 @@ class Application(tornado.web.Application): "BootMenuHeader" : boot.MenuHeaderModule, "BootMenuSeparator" : boot.MenuSeparatorModule, + # Docs + "DocsHeader" : docs.HeaderModule, + # People "Agent" : people.AgentModule, "CDR" : people.CDRModule, @@ -91,7 +94,6 @@ class Application(tornado.web.Application): # Wiki "WikiDiff" : wiki.WikiDiffModule, - "WikiNavbar" : wiki.WikiNavbarModule, "WikiList" : wiki.WikiListModule, # Misc diff --git a/src/web/docs.py b/src/web/docs.py index 0e87bb6c..4f20b5d9 100644 --- a/src/web/docs.py +++ b/src/web/docs.py @@ -4,6 +4,7 @@ import difflib import tornado.web from . import base +from . import ui_modules class PageHandler(base.BaseHandler): @property @@ -85,4 +86,29 @@ class PageHandler(base.BaseHandler): latest_revision = page.get_latest_revision() # Render page - self.render("wiki/page.html", page=page, latest_revision=latest_revision) + self.render("docs/page.html", page=page, latest_revision=latest_revision) + + +class HeaderModule(ui_modules.UIModule): + @property + def page(self): + """ + Returns the path of the page (without any actions) + """ + path = self.request.path.removeprefix("/docs") + + return "/".join((p for p in path.split("/") if not p.startswith("_"))) + + def render(self, suffix=None): + _ = self.locale.translate + + breadcrumbs = self.backend.wiki.make_breadcrumbs(self.page) + title = self.backend.wiki.get_page_title(self.page) + + if self.request.path.endswith("/_edit"): + suffix = _("Edit") + elif self.request.path.endswith("/_files"): + suffix = _("Files") + + return self.render_string("docs/modules/header.html", + breadcrumbs=breadcrumbs, page=self.page, page_title=title, suffix=suffix) diff --git a/src/web/wiki.py b/src/web/wiki.py index 42876fc2..674ebba0 100644 --- a/src/web/wiki.py +++ b/src/web/wiki.py @@ -391,40 +391,3 @@ class WikiListModule(ui_modules.UIModule): return self.render_string("wiki/modules/list.html", link_revision=link_revision, pages=pages, show_breadcrumbs=show_breadcrumbs, show_author=show_author, show_changes=show_changes) - - -class WikiNavbarModule(ui_modules.UIModule): - @property - def path(self): - """ - Returns the path of the page (without any actions) - """ - path = self.request.path.split("/") - - if path and path[-1].startswith("_"): - path.pop() - - return "/".join(path) - - def render(self, suffix=None): - _ = self.locale.translate - - # Make the path - page = self.request.path.split("/") - - # Drop the action bit - if page and page[-1].startswith("_"): - page.pop() - - page = "/".join(page) - - breadcrumbs = self.backend.wiki.make_breadcrumbs(page) - title = self.backend.wiki.get_page_title(page) - - if self.request.path.endswith("/_edit"): - suffix = _("Edit") - elif self.request.path.endswith("/_files"): - suffix = _("Files") - - return self.render_string("wiki/modules/navbar.html", - breadcrumbs=breadcrumbs, page=page, page_title=title, suffix=suffix)