Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Days summary #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions profile.templ
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ templ profileTemplate(params ProfilePageParams) {
title="RSS"
href={ "/" + params.Metadata.Npub() + ".rss" }
/>
<link
rel="alternate"
type="application/atom+xml"
title="RSS (Days Summary)"
href={ "/" + params.Metadata.Npub() + "-summary.rss" }
/>
@headCommonTemplate(params.HeadParams)
</head>
<body class="mb-16 bg-white text-gray-600 print:text-black dark:bg-neutral-900 dark:text-neutral-50">
Expand Down
33 changes: 32 additions & 1 deletion render_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ func renderProfile(w http.ResponseWriter, r *http.Request, code string) {
}

isRSS := false
if strings.HasSuffix(code, ".rss") {
isDaysSummary := false
if strings.HasSuffix(code, "-summary.rss") {
code = code[:len(code)-12]
isDaysSummary = true
} else if strings.HasSuffix(code, ".rss") {
code = code[:len(code)-4]
isRSS = true
}
Expand All @@ -45,6 +49,33 @@ func renderProfile(w http.ResponseWriter, r *http.Request, code string) {
ModifiedAt: data.modifiedAt,
LastNotes: data.renderableLastNotes,
})
} else if isDaysSummary {
w.Header().Add("content-type", "text/xml")
w.Header().Set("Cache-Control", "max-age=86400")
w.Write([]byte(XML_HEADER))
summaries := [][]EnhancedEvent{}
summary := []EnhancedEvent{}
from := ""
for _, note := range data.renderableLastNotes {
current := note.CreatedAt.Time().Format("2006/01/02")
if from != current {
if len(summary) > 0 {
summaries = append(summaries, summary)
summary = []EnhancedEvent{}
}
from = current
}
summary = append(summary, note)
}
if len(summary) > 0 {
summaries = append(summaries, summary)
}
err = RSSTemplate.Render(w, &RSSPage{
Host: s.Domain,
ModifiedAt: data.modifiedAt,
Metadata: data.metadata,
DaysSummaryNotes: summaries,
})
} else if isRSS {
w.Header().Add("content-type", "text/xml")
w.Header().Set("Cache-Control", "max-age=86400")
Expand Down
3 changes: 2 additions & 1 deletion xml-pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ type RSSPage struct {
Info *nip11.RelayInformationDocument

// for the profile and relay RSSs
LastNotes []EnhancedEvent
LastNotes []EnhancedEvent
DaysSummaryNotes [][]EnhancedEvent

// for the archive RSS
PathPrefix string
Expand Down
22 changes: 21 additions & 1 deletion xml/rss.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,24 @@
<updated>{{$ee.ModifiedAtStr}}</updated>
</entry>
{{end}}
</feed>

{{if gt (len .DaysSummaryNotes) 0}}
{{range $i, $summary := .DaysSummaryNotes}}
{{$first := index $summary 0}}
<entry>
<id>{{$first.Nevent}}</id>
<title>posts in {{$first.ModifiedAtStr}}</title>
<link rel="alternate" href="https://{{$.Host}}/{{$first.Nevent}}" />
<content type="html">
{{range $j, $ee := $summary}}
<div>
<p>posted at {{$ee.ModifiedAtStr}}</p>
<p>{{$ee.RssContent}}</p>
</div>
{{end}}
</content>
<updated>{{$first.ModifiedAtStr}}</updated>
</entry>
{{end}}
{{end}}
</feed>