make "s" (Settings) a global template function so we don't have to pass it around everywhere.

This commit is contained in:
fiatjaf
2023-10-07 08:20:10 -03:00
parent f169c01e67
commit 637cfa55e9
11 changed files with 18 additions and 23 deletions

View File

@@ -77,6 +77,7 @@ func main() {
}
funcMap := template.FuncMap{
"s": func() Settings { return s },
"basicFormatting": func(input string) string { return basicFormatting(input, false, false) },
"previewNotesFormatting": previewNotesFormatting,
"escapeString": html.EscapeString,

View File

@@ -262,7 +262,6 @@ func render(w http.ResponseWriter, r *http.Request) {
"parentNevent": data.parentNevent,
"authorRelays": data.authorRelays,
"oembed": oembed,
"s": s,
}
// if a mapping is not found fallback to raw

View File

@@ -86,7 +86,6 @@ func renderArchive(w http.ResponseWriter, r *http.Request) {
"paginationUrl": area,
"nextPage": fmt.Sprint(nextPage),
"prevPage": fmt.Sprint(prevPage),
"s": s,
}
if len(data) != 0 {

View File

@@ -37,7 +37,6 @@ func renderHomepage(w http.ResponseWriter, r *http.Request) {
}
params := map[string]any{
"s": s,
"npubs": npubs,
"lastNotes": lastNotes,
}

View File

@@ -74,7 +74,6 @@ func renderRelayPage(w http.ResponseWriter, r *http.Request) {
"proxy": "https://" + hostname + "/njump/proxy?src=",
"lastNotes": renderableLastNotes,
"modifiedAt": lastEventAt.Format("2006-01-02T15:04:05Z07:00"),
"s": s,
}
if len(renderableLastNotes) != 0 {

View File

@@ -8,9 +8,7 @@ func renderRobots(w http.ResponseWriter, r *http.Request) {
typ := "robots"
w.Header().Set("Cache-Control", "max-age=3600")
params := map[string]any{
"s": s,
}
params := map[string]any{}
if err := tmpl.ExecuteTemplate(w, templateMapping[typ], params); err != nil {
log.Error().Err(err).Msg("error rendering")

View File

@@ -26,14 +26,14 @@
(yet) working.
</p>
<p>
<i>njump</i> currently lives under {{ .s.CanonicalHost }}, you can
<i>njump</i> currently lives under {{ s.CanonicalHost }}, you can
reach it appending a Nostr (<a
href="https://github.com/nostr-protocol/nips/blob/master/19.md"
>NIP-19</a
>) entity (<code>npub</code>, <code>nevent</code>,
<code>naddr</code>, etc) after the domain:
<span class="exampleUrl"
>{{ .s.CanonicalHost }}/&lt;nip-19-entity&gt;</span
>{{ s.CanonicalHost }}/&lt;nip-19-entity&gt;</span
>.
</p>
<p>
@@ -62,7 +62,7 @@
<div class="try">
<form action="/try" method="POST">
<div class="tryForm">
<div>{{ .s.CanonicalHost }}/</div>
<div>{{ s.CanonicalHost }}/</div>
<input
id="nip19entity"
name="nip19entity"
@@ -140,11 +140,11 @@
>NIP-05</a
>
inspired permalink:
<span class="exampleUrl">{{ .s.CanonicalHost }}/&lt;nip-5&gt;</span
<span class="exampleUrl">{{ s.CanonicalHost }}/&lt;nip-5&gt;</span
>, for example:
<a href="/nvk.org">https://{{ .s.CanonicalHost }}/nvk.org</a> or
<a href="/nvk.org">https://{{ s.CanonicalHost }}/nvk.org</a> or
<a href="/mike@mikedilger.com"
>https://{{ .s.CanonicalHost }}/mike@mikedilger.com</a
>https://{{ s.CanonicalHost }}/mike@mikedilger.com</a
>.
</p>
<p>
@@ -156,10 +156,10 @@
<p>
You can have a view of the last content posted to a relay using
<span class="exampleUrl"
>{{ .s.CanonicalHost }}/r/&lt;relay-host&gt;</span
>{{ s.CanonicalHost }}/r/&lt;relay-host&gt;</span
>, for example:
<a href="/r/nostr.wine"
>https://{{ .s.CanonicalHost }}/r/nostr.wine</a
>https://{{ s.CanonicalHost }}/r/nostr.wine</a
>
</p>
<p>

View File

@@ -44,7 +44,7 @@
<link
rel="canonical"
href="https://{{.s.CanonicalHost}}/{{.nevent | escapeString }}"
href="https://{{s.CanonicalHost}}/{{.nevent | escapeString }}"
/>
<!---->
{{ if .oembed }}

View File

@@ -28,7 +28,7 @@
<link
rel="canonical"
href="https://{{.s.CanonicalHost}}/{{.npub | escapeString }}"
href="https://{{s.CanonicalHost}}/{{.npub | escapeString }}"
/>
<link
rel="sitemap"

View File

@@ -1,5 +1,5 @@
User-agent: *
Allow: /
Sitemap: https://{{.s.CanonicalHost}}/npubs-archive.xml
Sitemap: https://{{.s.CanonicalHost}}/relays-archive.xml
Sitemap: https://{{s.CanonicalHost}}/npubs-archive.xml
Sitemap: https://{{s.CanonicalHost}}/relays-archive.xml

View File

@@ -2,7 +2,7 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{{if .npub}}
<url>
<loc>https://{{.s.CanonicalHost}}/{{.npub | escapeString}}</loc>
<loc>https://{{s.CanonicalHost}}/{{.npub | escapeString}}</loc>
<lastmod>{{.modifiedAt | escapeString}}</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
@@ -10,7 +10,7 @@
{{end}}
{{if .hostname}}
<url>
<loc>https://{{.s.CanonicalHost}}/r/{{.hostname | escapeString}}</loc>
<loc>https://{{s.CanonicalHost}}/r/{{.hostname | escapeString}}</loc>
<lastmod>{{.modifiedAt | escapeString}}</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
@@ -19,7 +19,7 @@
{{if .lastNotes}}
{{range .lastNotes}}
<url>
<loc>https://{{.s.CanonicalHost}}/{{.Nevent | escapeString}}</loc>
<loc>https://{{s.CanonicalHost}}/{{.Nevent | escapeString}}</loc>
<lastmod>{{.ModifiedAt | escapeString}}</lastmod>
<changefreq>never</changefreq>
<priority>0.5</priority>
@@ -29,7 +29,7 @@
{{if .data}}
{{range $element := .data }}
<url>
<loc>https://{{.s.CanonicalHost}}/{{$.pathPrefix}}{{$element | trimProtocol | escapeString}}</loc>
<loc>https://{{s.CanonicalHost}}/{{$.pathPrefix}}{{$element | trimProtocol | escapeString}}</loc>
<lastmod>{{$.modifiedAt | escapeString}}</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>