mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-15 14:30:26 +00:00
169 lines
6.2 KiB
Plaintext
169 lines
6.2 KiB
Plaintext
{% import "net/http" %}
|
|
{% import "strings" %}
|
|
{% import "path" %}
|
|
{% import "os" %}
|
|
|
|
{% import "github.com/bouncepaw/mycorrhiza/cfg" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/hyphae" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/hypview" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/categories" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/l18n" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/mimetype" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/tree" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/user" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/util" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/viewutil" %}
|
|
|
|
{% func MediaMenu(rq *http.Request, h hyphae.Hypha, u *user.User) %}
|
|
{% code
|
|
lc := l18n.FromRequest(rq)
|
|
%}
|
|
<main class="main-width media-tab">
|
|
<h1>{%s= lc.Get("ui.media_title", &l18n.Replacements{"name": beautifulLink(h.CanonicalName())}) %}</h1>
|
|
{% switch h.(type) %}
|
|
{% case *hyphae.MediaHypha %}
|
|
<p class="explanation">{%s lc.Get("ui.media_tip") %} <a href="/help/en/media" class="shy-link">{%s lc.Get("ui.media_what_is") %}</a></p>
|
|
{% default %}
|
|
<p class="explanation">{%s lc.Get("ui.media_empty") %} <a href="/help/en/media" class="shy-link">{%s lc.Get("ui.media_what_is") %}</a></p>
|
|
{% endswitch %}
|
|
|
|
<section class="amnt-grid">
|
|
{% switch h := h.(type) %}
|
|
{% case *hyphae.MediaHypha %}
|
|
{% code
|
|
mime := mimetype.FromExtension(path.Ext(h.MediaFilePath()))
|
|
fileinfo, err := os.Stat(h.MediaFilePath()) %}
|
|
{% if err == nil %}
|
|
<fieldset class="amnt-menu-block">
|
|
<legend class="modal__title modal__title_small">{%s lc.Get("ui.media_stat") %}</legend>
|
|
<p class="modal__confirmation-msg"><b>{%s lc.Get("ui.media_stat_size") %}</b> {%s lc.GetPlural64("ui.media_size_value", fileinfo.Size())%}</p>
|
|
<p><b>{%s lc.Get("ui.media_stat_mime") %}</b> {%s mime %}</p>
|
|
</fieldset>
|
|
{% endif %}
|
|
|
|
{% if strings.HasPrefix(mime, "image/") %}
|
|
<fieldset class="amnt-menu-block">
|
|
<legend class="modal__title modal__title_small">{%s lc.Get("ui.media_include") %}</legend>
|
|
<p class="modal__confirmation-msg">{%s lc.Get("ui.media_include_tip") %}</p>
|
|
<pre class="codeblock"><code>img { {%s h.CanonicalName() %} }</code></pre>
|
|
</fieldset>
|
|
{% endif %}
|
|
{% endswitch %}
|
|
|
|
{% if u.CanProceed("upload-binary") %}
|
|
<form action="/upload-binary/{%s h.CanonicalName() %}"
|
|
method="post" enctype="multipart/form-data"
|
|
class="upload-binary modal amnt-menu-block">
|
|
<fieldset class="modal__fieldset">
|
|
<legend class="modal__title modal__title_small">{%s lc.Get("ui.media_new") %}</legend>
|
|
<p class="modal__confirmation-msg">{%s lc.Get("ui.media_new_tip") %}</p>
|
|
<label for="upload-binary__input"></label>
|
|
<input type="file" id="upload-binary__input" name="binary">
|
|
|
|
<button type="submit" class="btn stick-to-bottom" value="Upload">{%s lc.Get("ui.media_upload")%}</button>
|
|
</fieldset>
|
|
</form>
|
|
{% endif %}
|
|
|
|
|
|
{% switch h := h.(type) %}
|
|
{% case *hyphae.MediaHypha %}
|
|
{% if u.CanProceed("remove-media") %}
|
|
<form action="/remove-media/{%s h.CanonicalName() %}" method="post" class="modal amnt-menu-block" method="POST">
|
|
<fieldset class="modal__fieldset">
|
|
<legend class="modal__title modal__title_small">{%s lc.Get("ui.media_remove") %}</legend>
|
|
<p class="modal__confirmation-msg">{%s lc.Get("ui.media_remove_tip") %}</p>
|
|
<button type="submit" class="btn" value="Remove media">{%s lc.Get("ui.media_remove_button") %}</button>
|
|
</fieldset>
|
|
</form>
|
|
{% endif %}
|
|
{% endswitch %}
|
|
|
|
</section>
|
|
</main>
|
|
{% endfunc %}
|
|
|
|
If `contents` == "", a helpful message is shown instead.
|
|
|
|
If you rename .prevnext, change the docs too.
|
|
{% func Hypha(meta viewutil.Meta, h hyphae.Hypha, contents string) %}
|
|
{% code
|
|
siblings, subhyphae, prevHyphaName, nextHyphaName := tree.Tree(h.CanonicalName())
|
|
lc := meta.Lc
|
|
%}
|
|
<main class="main-width">
|
|
<section id="hypha">
|
|
{% if meta.U.CanProceed("edit") %}
|
|
<div class="btn btn_navititle">
|
|
<a class="btn__link_navititle" href="/edit/{%s h.CanonicalName() %}">{%s lc.Get("ui.edit_link") %}</a>
|
|
</div>
|
|
{% endif %}
|
|
|
|
{% if cfg.UseAuth && util.IsProfileName(h.CanonicalName()) && meta.U.Name == strings.TrimPrefix(h.CanonicalName(), cfg.UserHypha + "/") %}
|
|
<div class="btn btn_navititle">
|
|
<a class="btn__link_navititle" href="/logout">{%s lc.Get("ui.logout_link") %}</a>
|
|
</div>
|
|
{% if meta.U.Group == "admin" %}
|
|
<div class="btn btn_navititle">
|
|
<a class="btn__link_navititle" href="/admin">{%s lc.Get("ui.admin_panel") %}<a>
|
|
</div>
|
|
{% endif %}
|
|
{% endif %}
|
|
|
|
{%s= hypview.NaviTitle(meta, h.CanonicalName()) %}
|
|
{% switch h.(type) %}
|
|
{% case *hyphae.EmptyHypha %}
|
|
{%s= hypview.EmptyHypha(meta, h.CanonicalName()) %}
|
|
{% default %}
|
|
{%s= contents %}
|
|
{% endswitch %}
|
|
</section>
|
|
<section class="prevnext">
|
|
{% if prevHyphaName != "" %}
|
|
<a class="prevnext__el prevnext__prev" href="/hypha/{%s prevHyphaName %}" rel="prev">← {%s util.BeautifulName(path.Base(prevHyphaName)) %}</a>
|
|
{% endif %}
|
|
{% if nextHyphaName != "" %}
|
|
<a class="prevnext__el prevnext__next" href="/hypha/{%s nextHyphaName %}" rel="next">{%s util.BeautifulName(path.Base(nextHyphaName)) %} →</a>
|
|
{% endif %}
|
|
</section>
|
|
{% if strings.TrimSpace(subhyphae) != "" %}
|
|
<section class="subhyphae">
|
|
<h2 class="subhyphae__title">{%s lc.Get("ui.subhyphae") %}</h2>
|
|
<nav class="subhyphae__nav">
|
|
<ul class="subhyphae__list">
|
|
{%s= subhyphae %}
|
|
</ul>
|
|
</nav>
|
|
</section>
|
|
{% endif %}
|
|
<section id="hypha-bottom">
|
|
{%= hyphaInfo(meta, h) %}
|
|
</section>
|
|
</main>
|
|
{%s= categories.CategoryCard(meta, h.CanonicalName()) %}
|
|
{% if cfg.UseSiblingHyphaeSidebar %}
|
|
<aside class="sibling-hyphae layout-card">
|
|
<h2 class="sibling-hyphae__title layout-card__title">{%s lc.Get("ui.sibling_hyphae") %}</h2>
|
|
{%s= siblings %}
|
|
</aside>
|
|
{% endif %}
|
|
{%= viewScripts() %}
|
|
{% endfunc %}
|
|
|
|
{% func Revision(meta viewutil.Meta, h hyphae.Hypha, contents, revHash string) %}
|
|
<main class="main-width">
|
|
<section>
|
|
<p>{%s meta.Lc.Get("ui.revision_warning") %} <a href="/rev-text/{%s revHash %}/{%s h.CanonicalName() %}">{%s meta.Lc.Get("ui.revision_link") %}</a></p>
|
|
{%s= hypview.NaviTitle(meta, h.CanonicalName()) %}
|
|
{%s= contents %}
|
|
</section>
|
|
</main>
|
|
{%= viewScripts() %}
|
|
{% endfunc %}
|
|
|
|
{% func viewScripts() %}
|
|
{% for _, scriptPath := range cfg.ViewScripts %}
|
|
<script src="{%s scriptPath %}"></script>
|
|
{% endfor %}
|
|
{% endfunc %}
|