mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-18 14:54:24 +01:00
Add RSS for profiles and relays
This commit is contained in:
@@ -10,12 +10,17 @@ import (
|
||||
|
||||
func renderProfile(w http.ResponseWriter, r *http.Request, code string) {
|
||||
fmt.Println(r.URL.Path, "@.", r.Header.Get("user-agent"))
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
|
||||
isSitemap := false
|
||||
if strings.HasSuffix(code, ".xml") {
|
||||
isSitemap = true
|
||||
code = code[:len(code)-4]
|
||||
isSitemap = true
|
||||
}
|
||||
|
||||
isRSS := false
|
||||
if strings.HasSuffix(code, ".rss") {
|
||||
code = code[:len(code)-4]
|
||||
isRSS = true
|
||||
}
|
||||
|
||||
data, err := grabData(r.Context(), code, isSitemap)
|
||||
@@ -33,7 +38,27 @@ func renderProfile(w http.ResponseWriter, r *http.Request, code string) {
|
||||
errorPage.TemplateText()
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
ErrorTemplate.Render(w, errorPage)
|
||||
} else if !isSitemap {
|
||||
} else if isSitemap {
|
||||
w.Header().Add("content-type", "text/xml")
|
||||
w.Write([]byte(XML_HEADER))
|
||||
SitemapTemplate.Render(w, &SitemapPage{
|
||||
Host: s.Domain,
|
||||
ModifiedAt: data.modifiedAt,
|
||||
Npub: data.npub,
|
||||
LastNotes: data.renderableLastNotes,
|
||||
})
|
||||
} else if isRSS {
|
||||
w.Header().Add("content-type", "text/xml")
|
||||
w.Write([]byte(XML_HEADER))
|
||||
RSSTemplate.Render(w, &RSSPage{
|
||||
Host: s.Domain,
|
||||
ModifiedAt: data.modifiedAt,
|
||||
Npub: data.npub,
|
||||
Metadata: data.metadata,
|
||||
LastNotes: data.renderableLastNotes,
|
||||
})
|
||||
} else {
|
||||
w.Header().Add("content-type", "text/xml")
|
||||
err = ProfileTemplate.Render(w, &ProfilePage{
|
||||
HeadCommonPartial: HeadCommonPartial{IsProfile: true, TailwindDebugStuff: tailwindDebugStuff},
|
||||
DetailsPartial: DetailsPartial{
|
||||
@@ -56,15 +81,6 @@ func renderProfile(w http.ResponseWriter, r *http.Request, code string) {
|
||||
AuthorRelays: data.authorRelays,
|
||||
LastNotes: data.renderableLastNotes,
|
||||
})
|
||||
} else {
|
||||
w.Header().Add("content-type", "text/xml")
|
||||
w.Write([]byte(XML_HEADER))
|
||||
SitemapTemplate.Render(w, &SitemapPage{
|
||||
Host: s.Domain,
|
||||
ModifiedAt: data.modifiedAt,
|
||||
Npub: data.npub,
|
||||
LastNotes: data.renderableLastNotes,
|
||||
})
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user