1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 19:56:16 +00:00
mycorrhiza/templates/common.qtpl

54 lines
1.3 KiB
Plaintext
Raw Normal View History

{% import "net/http" %}
{% import "github.com/bouncepaw/mycorrhiza/user" %}
{% import "github.com/bouncepaw/mycorrhiza/util" %}
2020-10-02 15:31:59 +00:00
This is the <nav> seen on top of many pages.
{% code
type navEntry struct {
path string
title string
}
var navEntries = []navEntry{
{"page", "Hypha"},
{"edit", "Edit"},
{"text", "Raw text"},
{"history", "History"},
{"revision", "NOT REACHED"},
{"rename-ask", "Rename"},
{"delete-ask", "Delete"},
2020-10-02 15:31:59 +00:00
}
%}
{% func navHTML(rq *http.Request, hyphaName, navType string, revisionHash ...string) %}
{% code
u := user.FromRequest(rq).OrAnon()
%}
<nav class="navlinks">
2020-10-02 15:31:59 +00:00
<ul>
{%- for _, entry := range navEntries -%}
{%- if navType == "revision" && entry.path == "revision" -%}
<li><b>{%s revisionHash[0] %}</b></li>
{%- elseif navType == entry.path -%}
<li><b>{%s entry.title %}</b></li>
{%- elseif entry.path != "revision" && u.Group.CanAccessRoute(entry.path) -%}
2020-10-02 15:31:59 +00:00
<li><a href="/{%s entry.path %}/{%s hyphaName %}">{%s entry.title %}</a></li>
{%- endif -%}
{%- endfor -%}
{%s= userMenuHTML(u) %}
2020-10-02 15:31:59 +00:00
</ul>
</nav>
{% endfunc %}
{% func userMenuHTML(u *user.User) %}
{% if user.AuthUsed %}
<li class="navlinks__user">
{% if u.Group == user.UserAnon %}
<a href="/login">Login</a>
{% else %}
<a href="/page/{%s util.UserTree %}/{%s u.Name %}">{%s u.Name %}</a>
{% endif %}
</li>
{% endif %}
{% endfunc %}