Add gemini CTA to HTTP pages
This commit is contained in:
parent
6b3933282e
commit
b766eefe7c
@ -99,6 +99,9 @@ func (a *api) tplFuncs() template.FuncMap {
|
|||||||
"DateTimeFormat": func(t time.Time) string {
|
"DateTimeFormat": func(t time.Time) string {
|
||||||
return t.Format("2006-01-02")
|
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 {
|
func (a *api) mustParseBasedTpl(name string) *template.Template {
|
||||||
tpl := a.mustParseTpl(name)
|
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")))
|
tpl = template.Must(tpl.New("base.html").Parse(mustReadTplFile("base.html")))
|
||||||
return tpl
|
return tpl
|
||||||
}
|
}
|
||||||
@ -131,15 +135,19 @@ type tplData struct {
|
|||||||
Payload interface{}
|
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
|
// executeTemplate expects to be the final action in an http.Handler
|
||||||
func executeTemplate(
|
func executeTemplate(
|
||||||
rw http.ResponseWriter, r *http.Request,
|
rw http.ResponseWriter, r *http.Request,
|
||||||
tpl *template.Template, payload interface{},
|
tpl *template.Template, payload interface{},
|
||||||
) {
|
) {
|
||||||
|
|
||||||
tplData := tplData{
|
tplData := newTPLData(r, payload)
|
||||||
Payload: payload,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := tpl.Execute(rw, tplData); err != nil {
|
if err := tpl.Execute(rw, tplData); err != nil {
|
||||||
apiutil.InternalServerError(
|
apiutil.InternalServerError(
|
||||||
@ -164,7 +172,10 @@ func (a *api) renderDumbTplHandler(tplName string) http.Handler {
|
|||||||
tpl := a.mustParseBasedTpl(tplName)
|
tpl := a.mustParseBasedTpl(tplName)
|
||||||
|
|
||||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
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(
|
apiutil.InternalServerError(
|
||||||
rw, r, fmt.Errorf("rendering %q: %w", tplName, err),
|
rw, r, fmt.Errorf("rendering %q: %w", tplName, err),
|
||||||
)
|
)
|
||||||
|
@ -145,6 +145,8 @@ emailSubscribe.onclick = async () => {
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
{{ template "gemini-cta.html" . }}
|
||||||
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ template "base.html" . }}
|
{{ template "base.html" . }}
|
||||||
|
12
src/http/tpl/gemini-cta.html
Normal file
12
src/http/tpl/gemini-cta.html
Normal file
@ -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>
|
||||||
|
|
@ -50,6 +50,8 @@
|
|||||||
<li><a href="https://yamakan.place/palestine/#">Radio alHara</a> is another great internet radio station.</li>
|
<li><a href="https://yamakan.place/palestine/#">Radio alHara</a> is another great internet radio station.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
{{ template "gemini-cta.html" . }}
|
||||||
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ template "base.html" . }}
|
{{ template "base.html" . }}
|
||||||
|
@ -38,6 +38,8 @@
|
|||||||
</em></p>
|
</em></p>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
{{ template "gemini-cta.html" . }}
|
||||||
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ template "base.html" . }}
|
{{ template "base.html" . }}
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
</p>
|
</p>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
{{ template "gemini-cta.html" . }}
|
||||||
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ template "base.html" . }}
|
{{ template "base.html" . }}
|
||||||
|
Loading…
Reference in New Issue
Block a user