Add subscription/archive links to public pages.

This commit is contained in:
Kailash Nadh 2022-11-09 22:24:34 +05:30
parent ebf63b5bed
commit 23fb178ec4
6 changed files with 41 additions and 21 deletions

View file

@ -692,10 +692,12 @@ func initHTTPServer(app *App) *echo.Echo {
lo.Fatalf("error parsing public templates: %v", err) lo.Fatalf("error parsing public templates: %v", err)
} }
srv.Renderer = &tplRenderer{ srv.Renderer = &tplRenderer{
templates: tpl, templates: tpl,
RootURL: app.constants.RootURL, RootURL: app.constants.RootURL,
LogoURL: app.constants.LogoURL, LogoURL: app.constants.LogoURL,
FaviconURL: app.constants.FaviconURL} FaviconURL: app.constants.FaviconURL,
EnablePublicSubPage: app.constants.EnablePublicSubPage,
}
// Initialize the static file server. // Initialize the static file server.
fSrv := app.fs.FileServer() fSrv := app.fs.FileServer()

View file

@ -25,20 +25,22 @@ const (
// tplRenderer wraps a template.tplRenderer for echo. // tplRenderer wraps a template.tplRenderer for echo.
type tplRenderer struct { type tplRenderer struct {
templates *template.Template templates *template.Template
RootURL string RootURL string
LogoURL string LogoURL string
FaviconURL string FaviconURL string
EnablePublicSubPage bool
} }
// tplData is the data container that is injected // tplData is the data container that is injected
// into public templates for accessing data. // into public templates for accessing data.
type tplData struct { type tplData struct {
RootURL string RootURL string
LogoURL string LogoURL string
FaviconURL string FaviconURL string
Data interface{} EnablePublicSubPage bool
L *i18n.I18n Data interface{}
L *i18n.I18n
} }
type publicTpl struct { type publicTpl struct {
@ -83,11 +85,12 @@ var (
// Render executes and renders a template for echo. // Render executes and renders a template for echo.
func (t *tplRenderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error { func (t *tplRenderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
return t.templates.ExecuteTemplate(w, name, tplData{ return t.templates.ExecuteTemplate(w, name, tplData{
RootURL: t.RootURL, RootURL: t.RootURL,
LogoURL: t.LogoURL, LogoURL: t.LogoURL,
FaviconURL: t.FaviconURL, FaviconURL: t.FaviconURL,
Data: data, EnablePublicSubPage: t.EnablePublicSubPage,
L: c.Get("app").(*App).i18n, Data: data,
L: c.Get("app").(*App).i18n,
}) })
} }

View file

@ -15,6 +15,7 @@ body {
} }
a { a {
color: #0055d4; color: #0055d4;
text-decoration-color: #abcbfb;
} }
a:hover { a:hover {
color: #111; color: #111;
@ -57,6 +58,9 @@ input[disabled] {
.center { .center {
text-align: center; text-align: center;
} }
.right {
text-align: right;
}
.button { .button {
background: #0055d4; background: #0055d4;
padding: 15px 30px; padding: 15px 30px;
@ -145,7 +149,7 @@ input[disabled] {
font-size: 0.875em; font-size: 0.875em;
} }
.archive li { .archive li {
margin-bottom: 10px; margin-bottom: 15px;
} }
.pagination { .pagination {

View file

@ -16,6 +16,12 @@
{{ L.T "public.archiveEmpty" }} {{ L.T "public.archiveEmpty" }}
{{ end }} {{ end }}
{{ if .EnablePublicSubPage }}
<p class="right">
<a href="{{ .RootURL }}/subscription/form">Subscribe</a>
</p>
{{ end }}
{{ if gt .Data.TotalPages 1 }} {{ if gt .Data.TotalPages 1 }}
<div class="pagination">{{ .Data.Pagination }}</div> <div class="pagination">{{ .Data.Pagination }}</div>
{{ end }} {{ end }}

View file

@ -20,11 +20,13 @@
<div class="container wrap"> <div class="container wrap">
<header class="header"> <header class="header">
<div class="logo"> <div class="logo">
<a href="{{ if .EnablePublicSubPage }}{{ .RootURL}}/subscription/form{{ end }}">
{{ if ne .LogoURL "" }} {{ if ne .LogoURL "" }}
<img src="{{ .LogoURL }}" alt="{{ .Data.Title }}" /> <img src="{{ .LogoURL }}" alt="{{ .Data.Title }}" /></a>
{{ else }} {{ else }}
<img src="/public/static/logo.svg" alt="{{ .Data.Title }}" /> <img src="/public/static/logo.svg" alt="{{ .Data.Title }}" />
{{ end }} {{ end }}
</a>
</div> </div>
</header> </header>
{{ end }} {{ end }}

View file

@ -1,5 +1,5 @@
{{ define "subscription-form" }} {{ define "subscription-form" }}
{{ template "header" .}} {{ template "header" . }}
<section> <section>
<h2>{{ L.T "public.subTitle" }}</h2> <h2>{{ L.T "public.subTitle" }}</h2>
@ -30,6 +30,9 @@
</ul> </ul>
<p> <p>
<button type="submit" class="button">{{ L.T "public.sub" }}</button> <button type="submit" class="button">{{ L.T "public.sub" }}</button>
<p class="right">
<a href="{{ .RootURL }}/archive">{{ L.T "public.archiveTitle" }}</a>
</p>
</p> </p>
</div> </div>
</form> </form>