diff --git a/main.go b/main.go index 97632c5..a6737c0 100644 --- a/main.go +++ b/main.go @@ -106,6 +106,7 @@ func main() { mux.HandleFunc("/p/", redirectFromPSlash) mux.HandleFunc("/favicon.ico", redirectToFavicon) mux.HandleFunc("/embed/", renderEmbedjs) + mux.HandleFunc("/profile-lastnotes/", renderEvent) mux.HandleFunc("/", renderEvent) log.Print("listening at http://0.0.0.0:" + s.Port) diff --git a/pages.go b/pages.go index 54cafb4..cb58add 100644 --- a/pages.go +++ b/pages.go @@ -289,6 +289,18 @@ type ProfilePage struct { 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 ( //go:embed templates/embedded_profile.html tmplEmbeddedProfile string diff --git a/render_event.go b/render_event.go index 149f420..8938202 100644 --- a/render_event.go +++ b/render_event.go @@ -32,6 +32,11 @@ func renderEvent(w http.ResponseWriter, r *http.Request) { return } + if strings.HasPrefix(code, "profile-last-notes") { + renderProfile(w, r, code) + return + } + // decode the nip19 code we've received prefix, decoded, err := nip19.Decode(code) if err != nil { diff --git a/render_profile.go b/render_profile.go index b383002..cc2ef33 100644 --- a/render_profile.go +++ b/render_profile.go @@ -23,6 +23,12 @@ func renderProfile(w http.ResponseWriter, r *http.Request, code string) { isRSS = true } + isLastNotes := false + if strings.HasPrefix(code, "profile-last-notes") { + code = code[19:] + isLastNotes = true + } + data, err := grabData(r.Context(), code, isSitemap) if err != nil { w.Header().Set("Cache-Control", "max-age=60") @@ -35,10 +41,6 @@ func renderProfile(w http.ResponseWriter, r *http.Request, code string) { return } - if len(data.renderableLastNotes) != 0 { - w.Header().Set("Cache-Control", "max-age=3600") - } - if isSitemap { w.Header().Add("content-type", "text/xml") 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, 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 { w.Header().Add("content-type", "text/html") w.Header().Set("Cache-Control", "max-age=86400") diff --git a/templates/_last_notes.html b/templates/_last_notes.html new file mode 100644 index 0000000..6407ffa --- /dev/null +++ b/templates/_last_notes.html @@ -0,0 +1,32 @@ +{{if not (eq 0 (len .LastNotes))}} + +{{end}} diff --git a/templates/profile.html b/templates/profile.html index 3cb6658..fee1126 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -139,43 +139,27 @@ {{template "details" .DetailsPartial}} - - {{if not (eq 0 (len .LastNotes))}} - - {{end}} + + {{end}} + + + {{end}} +