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{ funcMap := template.FuncMap{
"s": func() Settings { return s },
"basicFormatting": func(input string) string { return basicFormatting(input, false, false) }, "basicFormatting": func(input string) string { return basicFormatting(input, false, false) },
"previewNotesFormatting": previewNotesFormatting, "previewNotesFormatting": previewNotesFormatting,
"escapeString": html.EscapeString, "escapeString": html.EscapeString,

View File

@@ -262,7 +262,6 @@ func render(w http.ResponseWriter, r *http.Request) {
"parentNevent": data.parentNevent, "parentNevent": data.parentNevent,
"authorRelays": data.authorRelays, "authorRelays": data.authorRelays,
"oembed": oembed, "oembed": oembed,
"s": s,
} }
// if a mapping is not found fallback to raw // 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, "paginationUrl": area,
"nextPage": fmt.Sprint(nextPage), "nextPage": fmt.Sprint(nextPage),
"prevPage": fmt.Sprint(prevPage), "prevPage": fmt.Sprint(prevPage),
"s": s,
} }
if len(data) != 0 { if len(data) != 0 {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,5 +1,5 @@
User-agent: * User-agent: *
Allow: / Allow: /
Sitemap: https://{{.s.CanonicalHost}}/npubs-archive.xml Sitemap: https://{{s.CanonicalHost}}/npubs-archive.xml
Sitemap: https://{{.s.CanonicalHost}}/relays-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"> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{{if .npub}} {{if .npub}}
<url> <url>
<loc>https://{{.s.CanonicalHost}}/{{.npub | escapeString}}</loc> <loc>https://{{s.CanonicalHost}}/{{.npub | escapeString}}</loc>
<lastmod>{{.modifiedAt | escapeString}}</lastmod> <lastmod>{{.modifiedAt | escapeString}}</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
<priority>0.8</priority> <priority>0.8</priority>
@@ -10,7 +10,7 @@
{{end}} {{end}}
{{if .hostname}} {{if .hostname}}
<url> <url>
<loc>https://{{.s.CanonicalHost}}/r/{{.hostname | escapeString}}</loc> <loc>https://{{s.CanonicalHost}}/r/{{.hostname | escapeString}}</loc>
<lastmod>{{.modifiedAt | escapeString}}</lastmod> <lastmod>{{.modifiedAt | escapeString}}</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
<priority>0.8</priority> <priority>0.8</priority>
@@ -19,7 +19,7 @@
{{if .lastNotes}} {{if .lastNotes}}
{{range .lastNotes}} {{range .lastNotes}}
<url> <url>
<loc>https://{{.s.CanonicalHost}}/{{.Nevent | escapeString}}</loc> <loc>https://{{s.CanonicalHost}}/{{.Nevent | escapeString}}</loc>
<lastmod>{{.ModifiedAt | escapeString}}</lastmod> <lastmod>{{.ModifiedAt | escapeString}}</lastmod>
<changefreq>never</changefreq> <changefreq>never</changefreq>
<priority>0.5</priority> <priority>0.5</priority>
@@ -29,7 +29,7 @@
{{if .data}} {{if .data}}
{{range $element := .data }} {{range $element := .data }}
<url> <url>
<loc>https://{{.s.CanonicalHost}}/{{$.pathPrefix}}{{$element | trimProtocol | escapeString}}</loc> <loc>https://{{s.CanonicalHost}}/{{$.pathPrefix}}{{$element | trimProtocol | escapeString}}</loc>
<lastmod>{{$.modifiedAt | escapeString}}</lastmod> <lastmod>{{$.modifiedAt | escapeString}}</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
<priority>0.5</priority> <priority>0.5</priority>