auth/web/baseof.qtpl

111 lines
2.2 KiB
Plaintext

{% import (
"runtime/debug"
"golang.org/x/text/language"
"golang.org/x/text/message"
"source.toby3d.me/toby3d/auth/internal/domain"
) %}
{% interface Page {
body()
head()
lang()
t(format message.Reference, args ...any)
title()
} %}
{% code type BaseOf struct {
Config *domain.Config
Language language.Tag
Printer *message.Printer
} %}
{% stripspace %}
{% func (p *BaseOf) lang() %}
{% if p.Language != language.Und %}
{%s p.Language.String() %}
{% else %}
en
{% endif %}
{% endfunc %}
{% endstripspace %}
{% collapsespace %}
{% func (p *BaseOf) title() %}
{%s p.Config.Name %}
{% endfunc %}
{% func (p *BaseOf) head() %}
{% comment %}https://evilmartians.com/chronicles/how-to-favicon-in-2021-six-files-that-fit-most-needs{% endcomment %}
<link rel="icon"
href="/favicon.ico"
sizes="any">
<link rel="icon"
href="/icon.svg"
type="image/svg+xml">
<link rel="apple-touch-icon"
href="/apple-touch-icon.png">
<link rel="manifest"
href="/manifest.webmanifest">
{% endfunc %}
{% func (p *BaseOf) body() %}{% endfunc %}
{% func Template(p Page) %}
<!DOCTYPE html>
<html class="page"
lang="{%= p.lang() %}">
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
{%= p.head() %}
<title>{%= p.title() %}</title>
</head>
<body class="page__body body">
{%= p.body() %}
{% code
var path, vcsRevision string
if bi, ok := debug.ReadBuildInfo(); ok {
path = bi.Path
for i := range bi.Settings {
if bi.Settings[i].Key != "vcs.revision" {
continue
}
vcsRevision = bi.Settings[i].Value
}
}
%}
{% if vcsRevision != "" %}
<footer>
<small>
{%= p.t("version") %}
<a href="https://{%s path %}/commit/{%s vcsRevision %}"
target="_blank">
{%s vcsRevision[:7] -%}
</a>
</small>
</footer>
{% endif %}
</body>
</html>
{% endfunc %}
{% func (p BaseOf) t(format message.Reference, args ...any) %}
{%s= p.Printer.Sprintf(format, args...) %}
{% endfunc %}
{% endcollapsespace %}