tmpl migration: homepage.html

This commit is contained in:
fiatjaf
2023-10-21 08:25:04 -03:00
parent a04f82764a
commit b6225e027d
3 changed files with 42 additions and 28 deletions

View File

@@ -120,6 +120,26 @@ func (*TelegramInstantViewPage) TemplateText() string {
return tmplTelegramInstantView
}
var (
//go:embed templates/homepage.html
tmplHomePage string
HomePageTemplate = tmpl.MustCompile(&HomePage{})
)
type HomePage struct {
HeadCommonPartial `tmpl:"head_common"`
TopPartial `tmpl:"top"`
FooterPartial `tmpl:"footer"`
Host string
Npubs []string
LastNotes []string
}
func (*HomePage) TemplateText() string {
return tmplHomePage
}
var (
//go:embed templates/archive.html
tmplArchive string

View File

@@ -10,7 +10,6 @@ import (
)
func renderHomepage(w http.ResponseWriter, r *http.Request) {
typ := "homepage"
w.Header().Set("Cache-Control", "max-age=3600")
npubsHex := cache.GetPaginatedkeys("pa", 1, 50)
@@ -36,13 +35,14 @@ func renderHomepage(w http.ResponseWriter, r *http.Request) {
lastNotes = append(lastNotes, nevent)
}
params := map[string]any{
"npubs": npubs,
"lastNotes": lastNotes,
}
err := HomePageTemplate.Render(w, &HomePage{
HeadCommonPartial: HeadCommonPartial{IsProfile: false},
if err := tmpls.ExecuteTemplate(w, templateMapping[typ], params); err != nil {
log.Error().Err(err).Msg("error rendering")
return
Host: s.Domain,
Npubs: npubs,
LastNotes: lastNotes,
})
if err != nil {
log.Error().Err(err).Msg("error rendering tmpl")
}
}

View File

@@ -26,16 +26,14 @@
(yet) working.
</p>
<p>
<i>njump</i> currently lives under {{ s.Domain }}, you can
reach it appending a Nostr
<i>njump</i> currently lives under {{ .Host }}, 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.Domain }}/&lt;nip-19-entity&gt;</span
>.
<span class="exampleUrl">{{ .Host }}/&lt;nip-19-entity&gt;</span>.
</p>
<p>
For example, here's
@@ -63,7 +61,7 @@
<div class="try">
<form action="/try" method="POST">
<div class="tryForm">
<div>{{ s.Domain }}/</div>
<div>{{ .Host }}/</div>
<input
id="nip19entity"
name="nip19entity"
@@ -141,11 +139,10 @@
>NIP-05</a
>
inspired permalink:
<span class="exampleUrl">{{ s.Domain }}/&lt;nip-5&gt;</span>,
for example:
<a href="/nvk.org">https://{{ s.Domain }}/nvk.org</a> or
<span class="exampleUrl">{{ .Host }}/&lt;nip-5&gt;</span>, for
example: <a href="/nvk.org">https://{{ .Host }}/nvk.org</a> or
<a href="/mike@mikedilger.com"
>https://{{ s.Domain }}/mike@mikedilger.com</a
>https://{{ .Host }}/mike@mikedilger.com</a
>.
</p>
<p>
@@ -167,12 +164,9 @@
<h2>Relays view</h2>
<p>
You can have a view of the last content posted to a relay using
<span class="exampleUrl"
>{{ s.Domain }}/r/&lt;relay-host&gt;</span
>, for example:
<a href="/r/nostr.wine"
>https://{{ s.Domain }}/r/nostr.wine</a
>
<span class="exampleUrl">{{ .Host }}/r/&lt;relay-host&gt;</span>,
for example:
<a href="/r/nostr.wine">https://{{ .Host }}/r/nostr.wine</a>
</p>
<p>
Some basic infos (<a
@@ -200,11 +194,11 @@
<script>
// JavaScript object with a list of 50 names
const entitiesList = [
{{range $element := .npubs }}
"{{ $element | escapeString}}",
{{range $element := .Npubs }}
"{{ $element }}",
{{end}}
{{range $element := .lastNotes }}
"{{ $element | escapeString}}",
{{range $element := .LastNotes }}
"{{ $element }}",
{{end}}
];