2020-11-16 15:26:03 +00:00
|
|
|
{% 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"},
|
2020-11-16 15:26:03 +00:00
|
|
|
{"delete-ask", "Delete"},
|
2020-10-02 15:31:59 +00:00
|
|
|
}
|
|
|
|
%}
|
|
|
|
|
2020-11-16 15:26:03 +00:00
|
|
|
{% func navHTML(rq *http.Request, hyphaName, navType string, revisionHash ...string) %}
|
2021-01-09 20:49:48 +00:00
|
|
|
{% code
|
|
|
|
u := user.FromRequest(rq)
|
2020-11-16 15:26:03 +00:00
|
|
|
%}
|
2021-01-09 20:49:48 +00:00
|
|
|
|
2020-11-16 15:26:03 +00:00
|
|
|
<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>
|
2021-01-09 20:49:48 +00:00
|
|
|
{%- elseif entry.path != "revision" && u.CanProceed(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 -%}
|
2020-11-16 15:26:03 +00:00
|
|
|
{%s= userMenuHTML(u) %}
|
2020-10-02 15:31:59 +00:00
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
{% endfunc %}
|
2020-11-16 15:26:03 +00:00
|
|
|
|
|
|
|
{% func userMenuHTML(u *user.User) %}
|
2020-11-29 17:09:02 +00:00
|
|
|
{% if user.AuthUsed %}
|
2020-11-16 15:26:03 +00:00
|
|
|
<li class="navlinks__user">
|
2021-01-09 20:49:48 +00:00
|
|
|
{% if u.Group == "anon" %}
|
2020-11-16 15:26:03 +00:00
|
|
|
<a href="/login">Login</a>
|
|
|
|
{% else %}
|
|
|
|
<a href="/page/{%s util.UserTree %}/{%s u.Name %}">{%s u.Name %}</a>
|
|
|
|
{% endif %}
|
|
|
|
</li>
|
2020-11-29 17:09:02 +00:00
|
|
|
{% endif %}
|
2020-11-16 15:26:03 +00:00
|
|
|
{% endfunc %}
|
|
|
|
|