mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-17 14:24:27 +01:00
Load profiles last notes asynchronously
This commit is contained in:
1
main.go
1
main.go
@@ -106,6 +106,7 @@ func main() {
|
|||||||
mux.HandleFunc("/p/", redirectFromPSlash)
|
mux.HandleFunc("/p/", redirectFromPSlash)
|
||||||
mux.HandleFunc("/favicon.ico", redirectToFavicon)
|
mux.HandleFunc("/favicon.ico", redirectToFavicon)
|
||||||
mux.HandleFunc("/embed/", renderEmbedjs)
|
mux.HandleFunc("/embed/", renderEmbedjs)
|
||||||
|
mux.HandleFunc("/profile-lastnotes/", renderEvent)
|
||||||
mux.HandleFunc("/", renderEvent)
|
mux.HandleFunc("/", renderEvent)
|
||||||
|
|
||||||
log.Print("listening at http://0.0.0.0:" + s.Port)
|
log.Print("listening at http://0.0.0.0:" + s.Port)
|
||||||
|
|||||||
12
pages.go
12
pages.go
@@ -289,6 +289,18 @@ type ProfilePage struct {
|
|||||||
|
|
||||||
func (*ProfilePage) TemplateText() string { return tmplProfile }
|
func (*ProfilePage) TemplateText() string { return tmplProfile }
|
||||||
|
|
||||||
|
var (
|
||||||
|
//go:embed templates/_last_notes.html
|
||||||
|
tmplLastNotes string
|
||||||
|
LastNotesTemplate = tmpl.MustCompile(&LastNotesPage{})
|
||||||
|
)
|
||||||
|
|
||||||
|
type LastNotesPage struct {
|
||||||
|
LastNotes []EnhancedEvent
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*LastNotesPage) TemplateText() string { return tmplLastNotes }
|
||||||
|
|
||||||
var (
|
var (
|
||||||
//go:embed templates/embedded_profile.html
|
//go:embed templates/embedded_profile.html
|
||||||
tmplEmbeddedProfile string
|
tmplEmbeddedProfile string
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ func renderEvent(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(code, "profile-last-notes") {
|
||||||
|
renderProfile(w, r, code)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// decode the nip19 code we've received
|
// decode the nip19 code we've received
|
||||||
prefix, decoded, err := nip19.Decode(code)
|
prefix, decoded, err := nip19.Decode(code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -23,6 +23,12 @@ func renderProfile(w http.ResponseWriter, r *http.Request, code string) {
|
|||||||
isRSS = true
|
isRSS = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isLastNotes := false
|
||||||
|
if strings.HasPrefix(code, "profile-last-notes") {
|
||||||
|
code = code[19:]
|
||||||
|
isLastNotes = true
|
||||||
|
}
|
||||||
|
|
||||||
data, err := grabData(r.Context(), code, isSitemap)
|
data, err := grabData(r.Context(), code, isSitemap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Header().Set("Cache-Control", "max-age=60")
|
w.Header().Set("Cache-Control", "max-age=60")
|
||||||
@@ -35,10 +41,6 @@ func renderProfile(w http.ResponseWriter, r *http.Request, code string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(data.renderableLastNotes) != 0 {
|
|
||||||
w.Header().Set("Cache-Control", "max-age=3600")
|
|
||||||
}
|
|
||||||
|
|
||||||
if isSitemap {
|
if isSitemap {
|
||||||
w.Header().Add("content-type", "text/xml")
|
w.Header().Add("content-type", "text/xml")
|
||||||
w.Header().Set("Cache-Control", "max-age=86400")
|
w.Header().Set("Cache-Control", "max-age=86400")
|
||||||
@@ -60,6 +62,14 @@ func renderProfile(w http.ResponseWriter, r *http.Request, code string) {
|
|||||||
Metadata: data.metadata,
|
Metadata: data.metadata,
|
||||||
LastNotes: data.renderableLastNotes,
|
LastNotes: data.renderableLastNotes,
|
||||||
})
|
})
|
||||||
|
} else if isLastNotes {
|
||||||
|
w.Header().Add("content-type", "text/html")
|
||||||
|
if len(data.renderableLastNotes) != 0 {
|
||||||
|
w.Header().Set("Cache-Control", "max-age=3600")
|
||||||
|
}
|
||||||
|
LastNotesTemplate.Render(w, &LastNotesPage{
|
||||||
|
LastNotes: data.renderableLastNotes,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
w.Header().Add("content-type", "text/html")
|
w.Header().Add("content-type", "text/html")
|
||||||
w.Header().Set("Cache-Control", "max-age=86400")
|
w.Header().Set("Cache-Control", "max-age=86400")
|
||||||
|
|||||||
32
templates/_last_notes.html
Normal file
32
templates/_last_notes.html
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{{if not (eq 0 (len .LastNotes))}}
|
||||||
|
<aside>
|
||||||
|
<div
|
||||||
|
class="-ml-4 mb-6 h-1.5 w-1/3 bg-zinc-100 dark:bg-zinc-700 sm:-ml-2.5"
|
||||||
|
></div>
|
||||||
|
<nav class="mb-6 leading-5">
|
||||||
|
<h2 class="text-2xl text-strongpink">Last Notes</h2>
|
||||||
|
{{range $i, $ee := .LastNotes}}
|
||||||
|
<a
|
||||||
|
class="my-8 block no-underline hover:-ml-6 hover:border-l-05rem hover:border-solid hover:border-l-gray-100 hover:pl-4 dark:hover:border-l-zinc-700"
|
||||||
|
href="/{{$ee.Nevent}}"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="-ml-2.5 mb-1.5 flex flex-row flex-wrap border-b-4 border-solid border-b-gray-100 pb-1 pl-2.5 dark:border-b-neutral-800"
|
||||||
|
>
|
||||||
|
<div class="text-sm text-strongpink">{{$ee.CreatedAtStr}}</div>
|
||||||
|
{{if $ee.IsReply}}
|
||||||
|
<div class="ml-2 text-sm text-gray-300 dark:text-gray-400">- reply</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="mt-0.5 max-h-40 basis-full overflow-hidden hover:text-strongpink"
|
||||||
|
_="on load if my scrollHeight > my offsetHeight add .gradient"
|
||||||
|
dir="auto"
|
||||||
|
>
|
||||||
|
{{$ee.Preview}}
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
{{end}}
|
||||||
|
</nav>
|
||||||
|
</aside>
|
||||||
|
{{end}}
|
||||||
@@ -139,43 +139,27 @@
|
|||||||
|
|
||||||
{{template "details" .DetailsPartial}}
|
{{template "details" .DetailsPartial}}
|
||||||
|
|
||||||
<!---->
|
<div
|
||||||
{{if not (eq 0 (len .LastNotes))}}
|
_="init fetch /profile-last-notes/{{.Npub}} then put the result into me end "
|
||||||
<aside>
|
>
|
||||||
<div
|
{{if not (eq 0 (len .LastNotes))}}
|
||||||
class="-ml-4 mb-6 h-1.5 w-1/3 bg-zinc-100 dark:bg-zinc-700 sm:-ml-2.5"
|
<aside>
|
||||||
></div>
|
<div
|
||||||
<nav class="mb-6 leading-5">
|
class="-ml-4 mb-6 h-1.5 w-1/3 bg-zinc-100 dark:bg-zinc-700 sm:-ml-2.5"
|
||||||
<h2 class="text-2xl text-strongpink">Last Notes</h2>
|
></div>
|
||||||
{{range $i, $ee := .LastNotes}}
|
<nav class="mb-6 leading-5">
|
||||||
<a
|
<h2 class="text-2xl text-strongpink">Last Notes</h2>
|
||||||
class="my-8 block no-underline hover:-ml-6 hover:border-l-05rem hover:border-solid hover:border-l-gray-100 hover:pl-4 dark:hover:border-l-zinc-700"
|
{{range $i, $ee := .LastNotes}}
|
||||||
href="/{{$ee.Nevent}}"
|
<a
|
||||||
>
|
class="my-8 block no-underline hover:-ml-6 hover:border-l-05rem hover:border-solid hover:border-l-gray-100 hover:pl-4 dark:hover:border-l-zinc-700"
|
||||||
<div
|
href="/{{$ee.Nevent}}"
|
||||||
class="-ml-2.5 mb-1.5 flex flex-row flex-wrap border-b-4 border-solid border-b-gray-100 pb-1 pl-2.5 dark:border-b-neutral-800"
|
|
||||||
>
|
>
|
||||||
<div class="text-sm text-strongpink">
|
</a>
|
||||||
{{$ee.CreatedAtStr}}
|
{{end}}
|
||||||
</div>
|
</nav>
|
||||||
{{if $ee.IsReply}}
|
</aside>
|
||||||
<div class="ml-2 text-sm text-gray-300 dark:text-gray-400">
|
{{end}}
|
||||||
- reply
|
</div>
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="mt-0.5 max-h-40 basis-full overflow-hidden hover:text-strongpink"
|
|
||||||
_="on load if my scrollHeight > my offsetHeight add .gradient"
|
|
||||||
dir="auto"
|
|
||||||
>
|
|
||||||
{{$ee.Preview}}
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
{{end}}
|
|
||||||
</nav>
|
|
||||||
</aside>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="-ml-4 mb-6 h-1.5 w-1/3 bg-zinc-100 dark:bg-zinc-700 sm:-ml-2.5"
|
class="-ml-4 mb-6 h-1.5 w-1/3 bg-zinc-100 dark:bg-zinc-700 sm:-ml-2.5"
|
||||||
|
|||||||
Reference in New Issue
Block a user