2020-11-16 15:26:03 +00:00
|
|
|
{% import "net/http" %}
|
2021-02-24 17:34:42 +00:00
|
|
|
{% import "strings" %}
|
2020-11-29 11:32:52 +00:00
|
|
|
{% import "path" %}
|
2021-02-24 17:34:42 +00:00
|
|
|
{% import "os" %}
|
2021-02-20 16:14:33 +00:00
|
|
|
|
2021-05-22 18:05:14 +00:00
|
|
|
{% import "github.com/bouncepaw/mycorrhiza/cfg" %}
|
2021-02-20 15:48:51 +00:00
|
|
|
{% import "github.com/bouncepaw/mycorrhiza/hyphae" %}
|
2022-04-01 20:52:56 +00:00
|
|
|
{% import "github.com/bouncepaw/mycorrhiza/categories" %}
|
2021-09-06 17:46:34 +00:00
|
|
|
{% import "github.com/bouncepaw/mycorrhiza/l18n" %}
|
2021-02-24 17:34:42 +00:00
|
|
|
{% import "github.com/bouncepaw/mycorrhiza/mimetype" %}
|
|
|
|
{% import "github.com/bouncepaw/mycorrhiza/tree" %}
|
2020-11-16 15:26:03 +00:00
|
|
|
{% import "github.com/bouncepaw/mycorrhiza/user" %}
|
2021-02-06 16:14:57 +00:00
|
|
|
{% import "github.com/bouncepaw/mycorrhiza/util" %}
|
2022-03-29 20:59:36 +00:00
|
|
|
{% import "github.com/bouncepaw/mycorrhiza/viewutil" %}
|
2021-02-24 17:34:42 +00:00
|
|
|
|
2022-03-20 21:24:40 +00:00
|
|
|
{% func MediaMenu(rq *http.Request, h hyphae.Hypha, u *user.User) %}
|
2021-09-06 17:46:34 +00:00
|
|
|
{% code
|
|
|
|
lc := l18n.FromRequest(rq)
|
|
|
|
%}
|
2022-02-26 07:33:09 +00:00
|
|
|
<main class="main-width media-tab">
|
|
|
|
<h1>{%s= lc.Get("ui.media_title", &l18n.Replacements{"name": beautifulLink(h.CanonicalName())}) %}</h1>
|
2022-02-19 08:26:38 +00:00
|
|
|
{% switch h.(type) %}
|
|
|
|
{% case *hyphae.MediaHypha %}
|
2022-02-26 07:33:09 +00:00
|
|
|
<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>
|
2022-02-19 08:26:38 +00:00
|
|
|
{% default %}
|
2022-02-26 07:33:09 +00:00
|
|
|
<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>
|
2022-02-19 08:26:38 +00:00
|
|
|
{% endswitch %}
|
2021-02-24 17:34:42 +00:00
|
|
|
|
|
|
|
<section class="amnt-grid">
|
2022-02-19 08:26:38 +00:00
|
|
|
{% switch h := h.(type) %}
|
|
|
|
{% case *hyphae.MediaHypha %}
|
2021-02-24 17:34:42 +00:00
|
|
|
{% code
|
2022-02-19 08:26:38 +00:00
|
|
|
mime := mimetype.FromExtension(path.Ext(h.MediaFilePath()))
|
|
|
|
fileinfo, err := os.Stat(h.MediaFilePath()) %}
|
2021-02-24 17:34:42 +00:00
|
|
|
{% if err == nil %}
|
|
|
|
<fieldset class="amnt-menu-block">
|
2022-02-26 07:33:09 +00:00
|
|
|
<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>
|
2021-02-24 17:34:42 +00:00
|
|
|
</fieldset>
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% if strings.HasPrefix(mime, "image/") %}
|
|
|
|
<fieldset class="amnt-menu-block">
|
2022-02-26 07:33:09 +00:00
|
|
|
<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>
|
2022-02-03 22:29:01 +00:00
|
|
|
<pre class="codeblock"><code>img { {%s h.CanonicalName() %} }</code></pre>
|
2021-02-24 17:34:42 +00:00
|
|
|
</fieldset>
|
|
|
|
{% endif %}
|
2022-02-19 08:26:38 +00:00
|
|
|
{% endswitch %}
|
2021-02-24 17:34:42 +00:00
|
|
|
|
|
|
|
{% if u.CanProceed("upload-binary") %}
|
2022-02-03 22:29:01 +00:00
|
|
|
<form action="/upload-binary/{%s h.CanonicalName() %}"
|
2021-02-24 17:34:42 +00:00
|
|
|
method="post" enctype="multipart/form-data"
|
2021-05-25 07:34:04 +00:00
|
|
|
class="upload-binary modal amnt-menu-block">
|
|
|
|
<fieldset class="modal__fieldset">
|
2022-02-26 07:33:09 +00:00
|
|
|
<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>
|
2021-05-25 07:34:04 +00:00
|
|
|
<label for="upload-binary__input"></label>
|
|
|
|
<input type="file" id="upload-binary__input" name="binary">
|
|
|
|
|
2022-02-26 07:33:09 +00:00
|
|
|
<button type="submit" class="btn stick-to-bottom" value="Upload">{%s lc.Get("ui.media_upload")%}</button>
|
2021-02-24 17:34:42 +00:00
|
|
|
</fieldset>
|
|
|
|
</form>
|
|
|
|
{% endif %}
|
|
|
|
|
2022-02-19 08:26:38 +00:00
|
|
|
|
|
|
|
{% switch h := h.(type) %}
|
|
|
|
{% case *hyphae.MediaHypha %}
|
2022-02-26 07:33:09 +00:00
|
|
|
{% if u.CanProceed("remove-media") %}
|
|
|
|
<form action="/remove-media/{%s h.CanonicalName() %}" method="post" class="modal amnt-menu-block" method="POST">
|
2022-02-19 08:26:38 +00:00
|
|
|
<fieldset class="modal__fieldset">
|
2022-02-26 07:33:09 +00:00
|
|
|
<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>
|
2022-02-19 08:26:38 +00:00
|
|
|
</fieldset>
|
|
|
|
</form>
|
|
|
|
{% endif %}
|
|
|
|
{% endswitch %}
|
2021-02-24 17:34:42 +00:00
|
|
|
|
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
{% endfunc %}
|
2020-08-31 17:52:26 +00:00
|
|
|
|
|
|
|
If `contents` == "", a helpful message is shown instead.
|
2021-09-23 09:17:50 +00:00
|
|
|
|
|
|
|
If you rename .prevnext, change the docs too.
|
2022-03-29 20:59:36 +00:00
|
|
|
{% func Hypha(meta viewutil.Meta, h hyphae.Hypha, contents string) %}
|
2021-02-20 16:14:33 +00:00
|
|
|
{% code
|
2022-02-03 22:29:01 +00:00
|
|
|
siblings, subhyphae, prevHyphaName, nextHyphaName := tree.Tree(h.CanonicalName())
|
2022-03-22 13:57:25 +00:00
|
|
|
lc := meta.Lc
|
2021-02-20 16:14:33 +00:00
|
|
|
%}
|
2021-01-26 05:41:57 +00:00
|
|
|
<main class="main-width">
|
2021-12-30 21:42:21 +00:00
|
|
|
<section id="hypha">
|
2022-03-22 13:57:25 +00:00
|
|
|
{% if meta.U.CanProceed("edit") %}
|
2022-01-02 18:31:54 +00:00
|
|
|
<div class="btn btn_navititle">
|
2022-02-03 22:29:01 +00:00
|
|
|
<a class="btn__link_navititle" href="/edit/{%s h.CanonicalName() %}">{%s lc.Get("ui.edit_link") %}</a>
|
2022-01-02 18:31:54 +00:00
|
|
|
</div>
|
|
|
|
{% endif %}
|
2022-01-02 18:21:08 +00:00
|
|
|
|
2022-03-22 13:57:25 +00:00
|
|
|
{% if cfg.UseAuth && util.IsProfileName(h.CanonicalName()) && meta.U.Name == strings.TrimPrefix(h.CanonicalName(), cfg.UserHypha + "/") %}
|
2022-01-02 18:31:54 +00:00
|
|
|
<div class="btn btn_navititle">
|
2022-01-02 18:21:08 +00:00
|
|
|
<a class="btn__link_navititle" href="/logout">{%s lc.Get("ui.logout_link") %}</a>
|
2022-01-02 18:31:54 +00:00
|
|
|
</div>
|
2022-03-22 13:57:25 +00:00
|
|
|
{% if meta.U.Group == "admin" %}
|
2022-01-02 18:31:54 +00:00
|
|
|
<div class="btn btn_navititle">
|
2022-01-08 21:13:36 +00:00
|
|
|
<a class="btn__link_navititle" href="/admin">{%s lc.Get("ui.admin_panel") %}<a>
|
2022-01-02 18:31:54 +00:00
|
|
|
</div>
|
|
|
|
{% endif %}
|
|
|
|
{% endif %}
|
2022-01-02 18:21:08 +00:00
|
|
|
|
2022-03-20 21:24:40 +00:00
|
|
|
{%s= NaviTitle(h) %}
|
2022-02-04 14:56:28 +00:00
|
|
|
{% switch h.(type) %}
|
|
|
|
{% case *hyphae.EmptyHypha %}
|
2022-03-22 13:57:25 +00:00
|
|
|
{%= nonExistentHyphaNotice(h, meta.U, meta.Lc) %}
|
2022-02-04 14:56:28 +00:00
|
|
|
{% default %}
|
|
|
|
{%s= contents %}
|
|
|
|
{% endswitch %}
|
2021-12-30 21:42:21 +00:00
|
|
|
</section>
|
2021-01-26 05:41:57 +00:00
|
|
|
<section class="prevnext">
|
|
|
|
{% if prevHyphaName != "" %}
|
2021-02-06 16:14:57 +00:00
|
|
|
<a class="prevnext__el prevnext__prev" href="/hypha/{%s prevHyphaName %}" rel="prev">← {%s util.BeautifulName(path.Base(prevHyphaName)) %}</a>
|
2021-01-26 05:41:57 +00:00
|
|
|
{% endif %}
|
|
|
|
{% if nextHyphaName != "" %}
|
2021-02-06 16:14:57 +00:00
|
|
|
<a class="prevnext__el prevnext__next" href="/hypha/{%s nextHyphaName %}" rel="next">{%s util.BeautifulName(path.Base(nextHyphaName)) %} →</a>
|
2021-01-26 05:41:57 +00:00
|
|
|
{% endif %}
|
|
|
|
</section>
|
2022-03-22 13:57:25 +00:00
|
|
|
{%= Subhyphae(subhyphae, meta.Lc) %}
|
2021-08-08 19:19:55 +00:00
|
|
|
<section id="hypha-bottom">
|
2022-03-22 13:57:25 +00:00
|
|
|
{%= hyphaInfo(meta, h) %}
|
2021-08-08 19:19:55 +00:00
|
|
|
</section>
|
2021-02-20 16:14:33 +00:00
|
|
|
</main>
|
2022-04-01 20:52:56 +00:00
|
|
|
{%s= categories.CategoryCard(meta, h.CanonicalName()) %}
|
2022-03-22 13:57:25 +00:00
|
|
|
{%= siblingHyphae(siblings, meta.Lc) %}
|
2021-05-22 18:05:14 +00:00
|
|
|
{%= viewScripts() %}
|
2021-02-20 16:14:33 +00:00
|
|
|
{% endfunc %}
|
|
|
|
|
2022-03-20 21:24:40 +00:00
|
|
|
{% func Revision(rq *http.Request, lc *l18n.Localizer, h hyphae.Hypha, contents, revHash string) %}
|
2021-02-20 16:14:33 +00:00
|
|
|
<main class="main-width">
|
2021-12-30 21:42:21 +00:00
|
|
|
<section>
|
2022-02-03 22:29:01 +00:00
|
|
|
<p>{%s lc.Get("ui.revision_warning") %} <a href="/rev-text/{%s revHash %}/{%s h.CanonicalName() %}">{%s lc.Get("ui.revision_link") %}</a></p>
|
2022-03-20 21:24:40 +00:00
|
|
|
{%s= NaviTitle(h) %}
|
2021-02-20 16:14:33 +00:00
|
|
|
{%s= contents %}
|
2021-12-30 21:42:21 +00:00
|
|
|
</section>
|
2021-02-20 16:14:33 +00:00
|
|
|
</main>
|
2021-05-22 18:05:14 +00:00
|
|
|
{%= viewScripts() %}
|
2021-02-20 16:14:33 +00:00
|
|
|
{% endfunc %}
|
2021-05-22 18:05:14 +00:00
|
|
|
|
|
|
|
{% func viewScripts() %}
|
|
|
|
{% for _, scriptPath := range cfg.ViewScripts %}
|
|
|
|
<script src="{%s scriptPath %}"></script>
|
|
|
|
{% endfor %}
|
2022-01-02 18:21:08 +00:00
|
|
|
{% endfunc %}
|