summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2023-01-24 13:12:46 +0100
committerBrian Picciano <mediocregopher@gmail.com>2023-01-24 13:13:07 +0100
commitb766eefe7cfaf334aeb607171250a2b4b9eaabf0 (patch)
tree10c20bd8d1f5f64a852b7668630eaff4ea02faf5
parent6b3933282e3aa9803636b2ba580aced5c202eaa9 (diff)
Add gemini CTA to HTTP pages
-rw-r--r--src/http/tpl.go19
-rw-r--r--src/http/tpl/follow.html2
-rw-r--r--src/http/tpl/gemini-cta.html12
-rw-r--r--src/http/tpl/index.html2
-rw-r--r--src/http/tpl/post.html2
-rw-r--r--src/http/tpl/posts.html2
6 files changed, 35 insertions, 4 deletions
diff --git a/src/http/tpl.go b/src/http/tpl.go
index 4af715a..0f6b531 100644
--- a/src/http/tpl.go
+++ b/src/http/tpl.go
@@ -99,6 +99,9 @@ func (a *api) tplFuncs() template.FuncMap {
"DateTimeFormat": func(t time.Time) string {
return t.Format("2006-01-02")
},
+ "SafeURL": func(u string) template.URL {
+ return template.URL(u)
+ },
}
}
@@ -123,6 +126,7 @@ func (a *api) mustParseTpl(name string) *template.Template {
func (a *api) mustParseBasedTpl(name string) *template.Template {
tpl := a.mustParseTpl(name)
+ tpl = template.Must(tpl.New("gemini-cta.html").Parse(mustReadTplFile("gemini-cta.html")))
tpl = template.Must(tpl.New("base.html").Parse(mustReadTplFile("base.html")))
return tpl
}
@@ -131,15 +135,19 @@ type tplData struct {
Payload interface{}
}
+func newTPLData(r *http.Request, payload interface{}) tplData {
+ return tplData{
+ Payload: payload,
+ }
+}
+
// executeTemplate expects to be the final action in an http.Handler
func executeTemplate(
rw http.ResponseWriter, r *http.Request,
tpl *template.Template, payload interface{},
) {
- tplData := tplData{
- Payload: payload,
- }
+ tplData := newTPLData(r, payload)
if err := tpl.Execute(rw, tplData); err != nil {
apiutil.InternalServerError(
@@ -164,7 +172,10 @@ func (a *api) renderDumbTplHandler(tplName string) http.Handler {
tpl := a.mustParseBasedTpl(tplName)
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
- if err := tpl.Execute(rw, nil); err != nil {
+
+ tplData := newTPLData(r, nil)
+
+ if err := tpl.Execute(rw, tplData); err != nil {
apiutil.InternalServerError(
rw, r, fmt.Errorf("rendering %q: %w", tplName, err),
)
diff --git a/src/http/tpl/follow.html b/src/http/tpl/follow.html
index 132706b..88fee46 100644
--- a/src/http/tpl/follow.html
+++ b/src/http/tpl/follow.html
@@ -145,6 +145,8 @@ emailSubscribe.onclick = async () => {
</li>
</ul>
+{{ template "gemini-cta.html" . }}
+
{{ end }}
{{ template "base.html" . }}
diff --git a/src/http/tpl/gemini-cta.html b/src/http/tpl/gemini-cta.html
new file mode 100644
index 0000000..06e3a22
--- /dev/null
+++ b/src/http/tpl/gemini-cta.html
@@ -0,0 +1,12 @@
+<hr/>
+
+<p>
+ This site can also be accessed via the gemini protocol:
+ <a href="{{ BlogGeminiURL "/" | SafeURL }}">
+ {{ BlogGeminiURL "/" }}
+ </a>
+</p>
+<p>
+ <a href="{{ PostURL "gemspace-tour" }}">What is gemini?</a>
+</p>
+
diff --git a/src/http/tpl/index.html b/src/http/tpl/index.html
index fdaf43f..0e5b58e 100644
--- a/src/http/tpl/index.html
+++ b/src/http/tpl/index.html
@@ -50,6 +50,8 @@
<li><a href="https://yamakan.place/palestine/#">Radio alHara</a> is another great internet radio station.</li>
</ul>
+ {{ template "gemini-cta.html" . }}
+
{{ end }}
{{ template "base.html" . }}
diff --git a/src/http/tpl/post.html b/src/http/tpl/post.html
index efef203..db69302 100644
--- a/src/http/tpl/post.html
+++ b/src/http/tpl/post.html
@@ -38,6 +38,8 @@
</em></p>
{{ end }}
+{{ template "gemini-cta.html" . }}
+
{{ end }}
{{ template "base.html" . }}
diff --git a/src/http/tpl/posts.html b/src/http/tpl/posts.html
index e6d226b..0701459 100644
--- a/src/http/tpl/posts.html
+++ b/src/http/tpl/posts.html
@@ -30,6 +30,8 @@
</p>
{{ end }}
+ {{ template "gemini-cta.html" . }}
+
{{ end }}
{{ template "base.html" . }}