1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 05:20:26 +00:00
mycorrhiza/views/stuff.qtpl
Timur Ismagilov 13f1752636 Document lock
2021-07-31 19:49:18 +05:00

261 lines
8.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{% import "path/filepath" %}
{% import "github.com/bouncepaw/mycorrhiza/cfg" %}
{% import "github.com/bouncepaw/mycorrhiza/hyphae" %}
{% import "github.com/bouncepaw/mycorrhiza/user" %}
{% import "github.com/bouncepaw/mycorrhiza/util" %}
{% func BaseHTML(title, body string, u *user.User, headElements ...string) %}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{%s title %}</title>
<link rel="shortcut icon" href="/static/favicon.ico">
<link rel="stylesheet" href="/static/style.css">
<script src="/static/shortcuts.js"></script>
{% for _, el := range headElements %}{%s= el %}{% endfor %}
</head>
<body>
<header>
<nav class="main-width top-bar">
<ul class="top-bar__wrapper">
<li class="top-bar__section top-bar__section_home">
<div class="top-bar__home-link-wrapper">
<a class="top-bar__home-link" href="/">{%s cfg.WikiName %}</a>
</div>
</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">
</form>
</li>
<li class="top-bar__section top-bar__section_auth">
{% if cfg.UseAuth %}
<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__link auth-links__login-link">Login</a>
{% else %}
<a href="/hypha/{%s cfg.UserHypha %}/{%s u.Name %}" class="auth-links__link 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__link 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__link auth-links__admin-link">Admin panel</a>
</li>
{% endif %}
</ul>
{% endif %}
</li>
<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>
</ul>
</nav>
</header>
{%s= body %}
<template id="dialog-template">
<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>
</div>
<div class="dialog__content"></div>
</div>
</template>
{%= CommonScripts() %}
<script src="/static/view.js"></script>
</body>
</html>
{% endfunc %}
{% func TitleSearchHTML(query string, generator func(string) <-chan string) %}
<div class="layout">
<main class="main-width title-search">
<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>
<ul class="title-search__results">
{% for hyphaName := range generator(query) %}
<li class="title-search__entry">
<a class="title-search__link wikilink" href="/hypha/{%s hyphaName %}">{%s util.BeautifulName(hyphaName) %}</a>
</li>
{% endfor %}
</main>
</div>
{% endfunc %}
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 %}
{% 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>
<ul class="help-topics__list">
<li><a href="/help/en">Main</a></li>
<li><a href="/help/en/hypha">Hypha</a>
<ul>
<li><a href="/help/en/attachment">Attachment</a></li>
</ul>
</li>
<li><a href="/help/en/mycomarkup">Mycomarkup</a></li>
<li>Interface
<ul>
<li><a href="/help/en/top_bar">Top bar</a>, new in 1.3</li>
<li><a href="/help/en/sibling_hyphae_section">Sibling hyphae</a></li>
<li>...</li>
</ul>
</li>
<li>Configuration (for administrators)
<ul>
<li><a href="/help/en/lock">Lock</a>, new in 1.3</li>
<li><a href="/help/en/whitelist">Whitelist</a>, new in 1.3</li>
<li><a href="/help/en/telegram">Telegram authorization</a>, new in 1.3</li>
<li>...</li>
</ul>
</li>
</ul>
</aside>
{% endfunc %}
{% 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 %}
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
{% endfor %}</ol>
</section>
<section>
<h2>Moderators</h2>
<ol>{% for _, name := range moderators %}
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
{% endfor %}</ol>
</section>
<section>
<h2>Editors</h2>
<ol>{% for _, name := range editors %}
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
{% endfor %}</ol>
</section>
</main>
</div>
{% endfunc %}
{% func HyphaListHTML() %}
<div class="layout">
<main class="main-width">
<h1>List of hyphae</h1>
<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>
</main>
</div>
{% endfunc %}
{% func AboutHTML() %}
<div class="layout">
<main class="main-width">
<section>
<h1>About {%s cfg.WikiName %}</h1>
<ul>
<li><b><a href="https://mycorrhiza.wiki">Mycorrhiza Wiki</a> version:</b> 1.3.0</li>
{%- if cfg.UseAuth -%}
<li><b>User count:</b> {%dul user.Count() %}</li>
<li><b>Home page:</b> <a href="/">{%s cfg.HomeHypha %}</a></li>
<li><b>Administrators:</b> {%- for i, username := range user.ListUsersWithGroup("admin") -%}
{%- if i > 0 -%}<span aria-hidden="true">, </span>
{%- endif -%}
<a href="/hypha/{%s cfg.UserHypha %}/{%s username %}">{%s username %}</a>{%- endfor -%}</li>
{%- 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>
</div>
{% endfunc %}
{% func CommonScripts() %}
{% for _, scriptPath := range cfg.CommonScripts %}
<script src="{%s scriptPath %}"></script>
{% endfor %}
{% endfunc %}