Skip to content

Commit

Permalink
Add subscription/archive links to public pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Nov 10, 2022
1 parent ebf63b5 commit 23fb178
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 21 deletions.
10 changes: 6 additions & 4 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,12 @@ func initHTTPServer(app *App) *echo.Echo {
lo.Fatalf("error parsing public templates: %v", err)
}
srv.Renderer = &tplRenderer{
templates: tpl,
RootURL: app.constants.RootURL,
LogoURL: app.constants.LogoURL,
FaviconURL: app.constants.FaviconURL}
templates: tpl,
RootURL: app.constants.RootURL,
LogoURL: app.constants.LogoURL,
FaviconURL: app.constants.FaviconURL,
EnablePublicSubPage: app.constants.EnablePublicSubPage,
}

// Initialize the static file server.
fSrv := app.fs.FileServer()
Expand Down
31 changes: 17 additions & 14 deletions cmd/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@ const (

// tplRenderer wraps a template.tplRenderer for echo.
type tplRenderer struct {
templates *template.Template
RootURL string
LogoURL string
FaviconURL string
templates *template.Template
RootURL string
LogoURL string
FaviconURL string
EnablePublicSubPage bool
}

// tplData is the data container that is injected
// into public templates for accessing data.
type tplData struct {
RootURL string
LogoURL string
FaviconURL string
Data interface{}
L *i18n.I18n
RootURL string
LogoURL string
FaviconURL string
EnablePublicSubPage bool
Data interface{}
L *i18n.I18n
}

type publicTpl struct {
Expand Down Expand Up @@ -83,11 +85,12 @@ var (
// Render executes and renders a template for echo.
func (t *tplRenderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
return t.templates.ExecuteTemplate(w, name, tplData{
RootURL: t.RootURL,
LogoURL: t.LogoURL,
FaviconURL: t.FaviconURL,
Data: data,
L: c.Get("app").(*App).i18n,
RootURL: t.RootURL,
LogoURL: t.LogoURL,
FaviconURL: t.FaviconURL,
EnablePublicSubPage: t.EnablePublicSubPage,
Data: data,
L: c.Get("app").(*App).i18n,
})
}

Expand Down
6 changes: 5 additions & 1 deletion static/public/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ body {
}
a {
color: #0055d4;
text-decoration-color: #abcbfb;
}
a:hover {
color: #111;
Expand Down Expand Up @@ -57,6 +58,9 @@ input[disabled] {
.center {
text-align: center;
}
.right {
text-align: right;
}
.button {
background: #0055d4;
padding: 15px 30px;
Expand Down Expand Up @@ -145,7 +149,7 @@ input[disabled] {
font-size: 0.875em;
}
.archive li {
margin-bottom: 10px;
margin-bottom: 15px;
}

.pagination {
Expand Down
6 changes: 6 additions & 0 deletions static/public/templates/archive.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ <h2>{{ L.T "public.archiveTitle" }}</h2>
{{ L.T "public.archiveEmpty" }}
{{ end }}

{{ if .EnablePublicSubPage }}
<p class="right">
<a href="{{ .RootURL }}/subscription/form">Subscribe</a>
</p>
{{ end }}

{{ if gt .Data.TotalPages 1 }}
<div class="pagination">{{ .Data.Pagination }}</div>
{{ end }}
Expand Down
4 changes: 3 additions & 1 deletion static/public/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
<div class="container wrap">
<header class="header">
<div class="logo">
<a href="{{ if .EnablePublicSubPage }}{{ .RootURL}}/subscription/form{{ end }}">
{{ if ne .LogoURL "" }}
<img src="{{ .LogoURL }}" alt="{{ .Data.Title }}" />
<img src="{{ .LogoURL }}" alt="{{ .Data.Title }}" /></a>
{{ else }}
<img src="/public/static/logo.svg" alt="{{ .Data.Title }}" />
{{ end }}
</a>
</div>
</header>
{{ end }}
Expand Down
5 changes: 4 additions & 1 deletion static/public/templates/subscription-form.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{ define "subscription-form" }}
{{ template "header" .}}
{{ template "header" . }}
<section>
<h2>{{ L.T "public.subTitle" }}</h2>

Expand Down Expand Up @@ -30,6 +30,9 @@ <h2>{{ L.T "globals.terms.lists" }}</h2>
</ul>
<p>
<button type="submit" class="button">{{ L.T "public.sub" }}</button>
<p class="right">
<a href="{{ .RootURL }}/archive">{{ L.T "public.archiveTitle" }}</a>
</p>
</p>
</div>
</form>
Expand Down

0 comments on commit 23fb178

Please sign in to comment.