2021-02-22 18:37:23 +00:00
{% import "path/filepath" %}
2021-05-09 09:36:39 +00:00
{% import "github.com/bouncepaw/mycorrhiza/cfg" %}
2021-02-22 18:37:23 +00:00
{% import "github.com/bouncepaw/mycorrhiza/hyphae" %}
2021-01-23 13:45:17 +00:00
{% import "github.com/bouncepaw/mycorrhiza/user" %}
2021-02-22 18:37:23 +00:00
{% import "github.com/bouncepaw/mycorrhiza/util" %}
2021-01-23 13:45:17 +00:00
2021-01-24 07:30:14 +00:00
{% func BaseHTML(title, body string, u *user.User, headElements ...string) %}
2020-08-31 17:52:26 +00:00
<!doctype html>
<html>
<head>
2021-02-22 18:19:28 +00:00
<meta charset="utf-8">
2021-06-12 13:51:28 +00:00
<meta name="viewport" content="width=device-width, initial-scale=1">
2020-08-31 17:52:26 +00:00
<title>{%s title %}</title>
2021-06-12 13:51:28 +00:00
<link rel="shortcut icon" href="/static/favicon.ico">
2021-06-13 05:40:06 +00:00
<link rel="stylesheet" href="/static/style.css">
<script src="/static/shortcuts.js"></script>
2020-12-17 12:59:59 +00:00
{% for _, el := range headElements %}{%s= el %}{% endfor %}
2020-08-31 17:52:26 +00:00
</head>
<body>
2021-01-23 19:00:58 +00:00
<header>
2021-07-13 20:52:33 +00:00
<nav class="main-width top-bar">
<ul class="top-bar__wrapper">
<li class="top-bar__section top-bar__section_home">
<a class="top-bar__home-link" href="/">{%s cfg.WikiName %}</a>
</li>
<li class="top-bar__section top-bar__section_search">
<form class="top-bar__search" method="GET" action="/title-search">
<input type="text" name="q" placeholder="Title search" class="top-bar__search-bar">
2021-07-12 17:13:54 +00:00
</form>
</li>
2021-07-13 20:52:33 +00:00
{% if cfg.UseAuth %}
<li class="top-bar__section top-bar__section_auth">
<ul class="top-bar__auth auth-links">
<li class="auth-links__box auth-links__user-box">
{% if u.Group == "anon" %}
<a href="/login" class="auth-links__login-link">Login</a>
{% else %}
<a href="/hypha/{%s cfg.UserHypha %}/{%s u.Name %}" class="auth-links__user-link">{%s util.BeautifulName(u.Name) %}</a>
{% endif %}
</li>
{% if cfg.AllowRegistration && u.Group == "anon" %}
<li class="auth-links__box auth-links__register-box">
<a href="/register" class="auth-links__register-link">Register</a>
</li>
{% endif %}
{% if u.Group == "admin" %}
<li class="auth-links__box auth-links__admin-box">
<a href="/admin" class="auth-links__admin-link">Admin panel</a>
</li>
{% endif %}
</ul>
</li>
{% endif %}
<li class="top-bar__section top-bar__section_highlights">
<ul class="top-bar__highlights">
{%- for _, link := range cfg.HeaderLinks -%}
{% if link.Href != "/" %}
<li class="top-bar__highlight">
<a class="top-bar__highlight-link" href="{%s link.Href %}">{%s link.Display %}</a>
</li>
{% endif %}
{%- endfor -%}
</ul>
</li>
2021-01-23 19:00:58 +00:00
</ul>
</nav>
</header>
2020-08-31 17:52:26 +00:00
{%s= body %}
2021-06-14 05:16:50 +00:00
<template id="dialog-template">
2021-06-14 06:50:52 +00:00
<div class="dialog-backdrop"></div>
<div class="dialog" tabindex="0">
<div class="dialog__header">
<h1 class="dialog__title"></h1>
<button class="dialog__close-button" aria-label="Close this dialog"></button>
2021-06-14 05:16:50 +00:00
</div>
2021-06-14 06:50:52 +00:00
<div class="dialog__content"></div>
2021-06-14 05:16:50 +00:00
</div>
</template>
2021-07-01 09:45:29 +00:00
{%= CommonScripts() %}
2020-08-31 17:52:26 +00:00
</body>
</html>
{% endfunc %}
2021-07-12 17:05:50 +00:00
{% func TitleSearchHTML(query string, generator func(string) <-chan string) %}
2021-07-12 13:25:57 +00:00
<div class="layout">
2021-07-12 17:05:50 +00:00
<main class="main-width title-search">
2021-07-12 16:48:57 +00:00
<h1>Search results for ‘ {%s query %}’ </h1>
<p>Every hypha name has been compared with the query. Hyphae that have matched the query are listed below.</p>
2021-07-12 17:05:50 +00:00
<ul class="title-search__results">
2021-07-12 13:25:57 +00:00
{% for hyphaName := range generator(query) %}
2021-07-12 17:05:50 +00:00
<li class="title-search__entry">
<a class="title-search__link wikilink" href="/hypha/{%s hyphaName %}">{%s util.BeautifulName(hyphaName) %}</a>
2021-07-12 13:25:57 +00:00
</li>
{% endfor %}
</main>
</div>
{% endfunc %}
2021-07-12 17:55:36 +00:00
It outputs a poorly formatted JSON, but it works and is valid.
{% func TitleSearchJSON(query string, generator func(string) <-chan string) %}
{% code
// Lol
counter := 0
%}
{
"source_query": "{%s query %}",
"results": [
{% for hyphaName := range generator(query) %}
{% if counter > 0 %}, {% endif %}{
"canonical_name": "{%s hyphaName %}",
"beautiful_name": "{%s util.BeautifulName(hyphaName) %}",
"url": "{%s cfg.URL + "/hypha/" + hyphaName %}"
}{% code counter++ %}
{% endfor %}
]
}
{% endfunc %}
2021-07-12 09:58:20 +00:00
{% func HelpHTML(content string) %}
<div class="layout">
<main class="main-width help">
<article>
{%s= content %}
</article>
</main>
{%s= helpTopicsHTML() %}
</div>
{% endfunc %}
{% func HelpEmptyErrorHTML() %}
<h1>This entry does not exist!</h1>
<p>Try finding a different entry that would help you.</p>
<p>If you want to write this entry by yourself, consider <a class="wikilink wikilink_external wikilink_https" href="https://github.com/bouncepaw/mycorrhiza">contributing</a> to Mycorrhiza Wiki directly.</p>
{% endfunc %}
{% func helpTopicsHTML() %}
<aside class="help-topics layout-card">
<h2 class="layout-card__title">Help topics</h2>
2021-07-12 10:13:12 +00:00
<ul class="help-topics__list">
2021-07-12 09:58:20 +00:00
<li>
2021-07-12 10:01:53 +00:00
<a href="/help/en">Main</a>
2021-07-12 09:58:20 +00:00
</li>
<li>
<a href="/help/en/hypha">Hypha</a>
<ul>
<li>
<a href="/help/en/attachment">Attachment</a>
</li>
</ul
</li>
</ul>
</aside>
{% endfunc %}
2021-01-30 18:21:50 +00:00
{% func UserListHTML() %}
<div class="layout">
<main class="main-width user-list">
<h1>List of users</h1>
{% code
var (
admins = make([]string, 0)
moderators = make([]string, 0)
editors = make([]string, 0)
)
for u := range user.YieldUsers() {
switch u.Group {
case "admin":
admins = append(admins, u.Name)
case "moderator":
moderators = append(moderators, u.Name)
case "editor", "trusted":
editors = append(editors, u.Name)
}
}
%}
<section>
<h2>Admins</h2>
<ol>{% for _, name := range admins %}
2021-06-14 07:13:29 +00:00
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
2021-01-30 18:21:50 +00:00
{% endfor %}</ol>
</section>
<section>
<h2>Moderators</h2>
<ol>{% for _, name := range moderators %}
2021-06-14 07:13:29 +00:00
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
2021-01-30 18:21:50 +00:00
{% endfor %}</ol>
</section>
<section>
<h2>Editors</h2>
<ol>{% for _, name := range editors %}
2021-06-14 07:13:29 +00:00
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
2021-01-30 18:21:50 +00:00
{% endfor %}</ol>
</section>
</main>
</div>
{% endfunc %}
2021-02-22 18:37:23 +00:00
{% func HyphaListHTML() %}
2021-01-26 05:41:57 +00:00
<div class="layout">
<main class="main-width">
2020-08-31 18:16:22 +00:00
<h1>List of hyphae</h1>
2021-02-22 18:37:23 +00:00
<p>This wiki has {%d hyphae.Count() %} hyphae.</p>
<ul class="hypha-list">
{% for h := range hyphae.YieldExistingHyphae() %}
<li class="hypha-list__entry">
<a class="hypha-list__link" href="/hypha/{%s h.Name %}">{%s util.BeautifulName(h.Name) %}</a>
{% if h.BinaryPath != "" %}
<span class="hypha-list__amnt-type">{%s filepath.Ext(h.BinaryPath)[1:] %}</span>
{% endif %}
</li>
{% endfor %}
</ul>
2020-08-31 17:52:26 +00:00
</main>
2021-01-26 05:41:57 +00:00
</div>
2020-08-31 17:52:26 +00:00
{% endfunc %}
2020-08-31 18:16:22 +00:00
2021-01-23 13:45:17 +00:00
{% func AboutHTML() %}
2021-01-26 05:41:57 +00:00
<div class="layout">
<main class="main-width">
2021-01-23 13:45:17 +00:00
<section>
2021-05-09 09:36:39 +00:00
<h1>About {%s cfg.WikiName %}</h1>
2021-01-23 13:45:17 +00:00
<ul>
2021-07-05 04:22:17 +00:00
<li><b><a href="https://mycorrhiza.wiki">Mycorrhiza Wiki</a> version:</b> 1.3.0</li>
2021-07-02 08:20:03 +00:00
{%- if cfg.UseAuth -%}
<li><b>User count:</b> {%dul user.Count() %}</li>
2021-05-09 09:36:39 +00:00
<li><b>Home page:</b> <a href="/">{%s cfg.HomeHypha %}</a></li>
2021-01-23 13:45:17 +00:00
<li><b>Administrators:</b> {%- for i, username := range user.ListUsersWithGroup("admin") -%}
{%- if i > 0 -%}<span aria-hidden="true">, </span>
{%- endif -%}
2021-06-14 07:13:29 +00:00
<a href="/hypha/{%s cfg.UserHypha %}/{%s username %}">{%s username %}</a>{%- endfor -%}</li>
2021-01-23 13:45:17 +00:00
{%- else -%}
<li>This wiki does not use authorization</li>
{%- endif -%}
</ul>
<p>See <a href="/list">/list</a> for information about hyphae on this wiki.</p>
</section>
</main>
2021-01-26 05:41:57 +00:00
</div>
2021-01-23 13:45:17 +00:00
{% endfunc %}
2021-02-22 18:19:28 +00:00
2021-07-01 09:45:29 +00:00
{% func CommonScripts() %}
{% for _, scriptPath := range cfg.CommonScripts %}
2021-05-22 18:05:14 +00:00
<script src="{%s scriptPath %}"></script>
{% endfor %}
2021-06-29 10:34:36 +00:00
{% endfunc %}