diff options
author | Drew DeVault <sir@cmpwn.com> | 2020-05-13 10:58:22 -0400 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-05-13 16:58:48 +0200 |
commit | 1cf95af41ea24ab76cba8a0761d349b65c08c294 (patch) | |
tree | f7a5fd00a63498f00768aeba140b68a5d4a74431 | |
parent | 0191b739969e00cdba0faa5a05159fd5f83d5d9e (diff) | |
download | alps-1cf95af41ea24ab76cba8a0761d349b65c08c294.tar.gz alps-1cf95af41ea24ab76cba8a0761d349b65c08c294.zip |
Add <meta refresh> to mailbox view
This causes the mailbox to automatically reload the page every 60
seconds, without JavaScript.
This also updates the base template data to include the full URL, and
replaces the earlier "Path" field with a pre-split array of path
components, which is more immediately useful to most templates given the
limitations of string munging with text/template primitives.
26 files changed, 34 insertions, 27 deletions
diff --git a/plugins/base/public/compose.html b/plugins/base/public/compose.html index 2deb24a..df1e360 100644 --- a/plugins/base/public/compose.html +++ b/plugins/base/public/compose.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .}} <h1>alps</h1> diff --git a/plugins/base/public/login.html b/plugins/base/public/login.html index 0391ed1..77f53ba 100644 --- a/plugins/base/public/login.html +++ b/plugins/base/public/login.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .}} <h1>alps</h1> diff --git a/plugins/base/public/mailbox.html b/plugins/base/public/mailbox.html index 1e376ba..45729d1 100644 --- a/plugins/base/public/mailbox.html +++ b/plugins/base/public/mailbox.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .}} <h1>alps</h1> diff --git a/plugins/base/public/message.html b/plugins/base/public/message.html index 4d5edfa..38b41c5 100644 --- a/plugins/base/public/message.html +++ b/plugins/base/public/message.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .}} <h1>alps</h1> diff --git a/plugins/base/public/settings.html b/plugins/base/public/settings.html index 6a7f8ba..7acacb5 100644 --- a/plugins/base/public/settings.html +++ b/plugins/base/public/settings.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .}} <h1>alps</h1> diff --git a/plugins/caldav/public/calendar.html b/plugins/caldav/public/calendar.html index 8a0a390..c23c555 100644 --- a/plugins/caldav/public/calendar.html +++ b/plugins/caldav/public/calendar.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .}} <h1>alps</h1> diff --git a/plugins/caldav/public/event.html b/plugins/caldav/public/event.html index a07f663..f3c7652 100644 --- a/plugins/caldav/public/event.html +++ b/plugins/caldav/public/event.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .}} <h1>alps</h1> diff --git a/plugins/carddav/public/address-book.html b/plugins/carddav/public/address-book.html index a9ab9c5..e1e735f 100644 --- a/plugins/carddav/public/address-book.html +++ b/plugins/carddav/public/address-book.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .}} <h1>alps</h1> diff --git a/plugins/carddav/public/address-object.html b/plugins/carddav/public/address-object.html index b6e731e..5423d9f 100644 --- a/plugins/carddav/public/address-object.html +++ b/plugins/carddav/public/address-object.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .}} <h1>alps</h1> diff --git a/plugins/carddav/public/update-address-object.html b/plugins/carddav/public/update-address-object.html index 4769e97..dd4d087 100644 --- a/plugins/carddav/public/update-address-object.html +++ b/plugins/carddav/public/update-address-object.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .}} <h1>alps</h1> diff --git a/renderer.go b/renderer.go index 5471158..3379233 100644 --- a/renderer.go +++ b/renderer.go @@ -5,7 +5,9 @@ import ( "html/template" "io" "io/ioutil" + "net/url" "os" + "strings" "github.com/labstack/echo/v4" ) @@ -14,7 +16,8 @@ const themesDir = "themes" // GlobalRenderData contains data available in all templates. type GlobalRenderData struct { - Path string + Path []string + URL *url.URL LoggedIn bool @@ -71,7 +74,8 @@ func NewBaseRenderData(ctx *Context) *BaseRenderData { global.Username = ctx.Session.username } - global.Path = ctx.Request().URL.String() + global.URL = ctx.Request().URL + global.Path = strings.Split(global.URL.Path, "/")[1:] return &BaseRenderData{ GlobalData: global, diff --git a/themes/alps/compose.html b/themes/alps/compose.html index 7b58a5f..6bd516e 100644 --- a/themes/alps/compose.html +++ b/themes/alps/compose.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .}} {{template "nav.html" .}} diff --git a/themes/alps/head.html b/themes/alps/head.html index a6f679f..899f7d6 100644 --- a/themes/alps/head.html +++ b/themes/alps/head.html @@ -4,6 +4,9 @@ <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="theme-color" content="#ffffff"> + {{- if eq (index .GlobalData.Path 0) "mailbox"}} + <meta id="refresh" http-equiv="refresh" content="60"> + {{end -}} <title>Webmail</title> <link rel="stylesheet" href="/themes/alps/assets/style.css"> </head> diff --git a/themes/alps/login.html b/themes/alps/login.html index cc21966..f599535 100644 --- a/themes/alps/login.html +++ b/themes/alps/login.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .}} <h1>alps webmail</h1> <form method="post" action="/login"> diff --git a/themes/alps/mailbox.html b/themes/alps/mailbox.html index 6453d69..8e3331f 100644 --- a/themes/alps/mailbox.html +++ b/themes/alps/mailbox.html @@ -1,5 +1,5 @@ -{{template "head.html"}} -{{template "nav.html" . }} +{{template "head.html" .}} +{{template "nav.html" .}} <div class="page-wrap"> <aside> diff --git a/themes/alps/message.html b/themes/alps/message.html index 6d383ae..9257967 100644 --- a/themes/alps/message.html +++ b/themes/alps/message.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .}} {{template "nav.html" .}} <div class="page-wrap"> diff --git a/themes/alps/messages-header.html b/themes/alps/messages-header.html index 9384fb6..8e018db 100644 --- a/themes/alps/messages-header.html +++ b/themes/alps/messages-header.html @@ -21,7 +21,7 @@ {{ end }} - <a href="{{ .GlobalData.Path }}" class="button-link">Refresh</a> + <a href="{{ .GlobalData.URL.String }}" class="button-link">Refresh</a> </div> <form action="" method="post" class="actions-search"> diff --git a/themes/sourcehut/address-book.html b/themes/sourcehut/address-book.html index c5600d6..44abbe2 100644 --- a/themes/sourcehut/address-book.html +++ b/themes/sourcehut/address-book.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .Global}} {{template "nav.html" .Global}} <div class="container-fluid"> diff --git a/themes/sourcehut/address-object.html b/themes/sourcehut/address-object.html index 1ab445f..6fb5f6c 100644 --- a/themes/sourcehut/address-object.html +++ b/themes/sourcehut/address-object.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .Global}} {{template "nav.html" .Global}} {{$fn := .AddressObject.Card.Value "FN"}} diff --git a/themes/sourcehut/calendar.html b/themes/sourcehut/calendar.html index ec15ae8..d0cfac0 100644 --- a/themes/sourcehut/calendar.html +++ b/themes/sourcehut/calendar.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .Global}} {{template "nav.html" .Global}} <div class="container-fluid"> diff --git a/themes/sourcehut/compose.html b/themes/sourcehut/compose.html index 7538a36..8f73538 100644 --- a/themes/sourcehut/compose.html +++ b/themes/sourcehut/compose.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .Global}} {{template "nav.html" .Global}} <div class="container-fluid"> diff --git a/themes/sourcehut/event.html b/themes/sourcehut/event.html index a298ce1..3740166 100644 --- a/themes/sourcehut/event.html +++ b/themes/sourcehut/event.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .Global}} {{template "nav.html" .Global}} {{$event := index .Event.Data.Events 0}} diff --git a/themes/sourcehut/login.html b/themes/sourcehut/login.html index 63edfd8..65605b4 100644 --- a/themes/sourcehut/login.html +++ b/themes/sourcehut/login.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .Global}} {{template "nav.html" .Global}} <div class="container"> diff --git a/themes/sourcehut/mailbox.html b/themes/sourcehut/mailbox.html index e360f25..58eb52b 100644 --- a/themes/sourcehut/mailbox.html +++ b/themes/sourcehut/mailbox.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .Global}} {{template "nav.html" .Global}} <!-- TODO: Share tabs if reasonable --> diff --git a/themes/sourcehut/message.html b/themes/sourcehut/message.html index 1e4197f..077d33c 100644 --- a/themes/sourcehut/message.html +++ b/themes/sourcehut/message.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .Global}} {{template "nav.html" .Global}} <div class="container-fluid"> diff --git a/themes/sourcehut/settings.html b/themes/sourcehut/settings.html index 292d5cc..c197789 100644 --- a/themes/sourcehut/settings.html +++ b/themes/sourcehut/settings.html @@ -1,4 +1,4 @@ -{{template "head.html"}} +{{template "head.html" .Global}} {{template "nav.html" .Global}} <div class="container-fluid"> |