diff --git a/cmd/archive.go b/cmd/archive.go index d2fdf75..197f79a 100644 --- a/cmd/archive.go +++ b/cmd/archive.go @@ -6,6 +6,7 @@ import ( "html/template" "net/http" + "github.com/gorilla/feeds" "github.com/knadh/listmonk/internal/manager" "github.com/knadh/listmonk/models" "github.com/labstack/echo/v4" @@ -46,6 +47,42 @@ func handleGetCampaignArchives(c echo.Context) error { return c.JSON(200, okResp{out}) } +// handleGetCampaignArchivesFeed renders the public campaign archives RSS feed. +func handleGetCampaignArchivesFeed(c echo.Context) error { + var ( + app = c.Get("app").(*App) + pg = app.paginator.NewFromURL(c.Request().URL.Query()) + ) + + camps, _, err := getCampaignArchives(pg.Offset, pg.Limit, app) + if err != nil { + return err + } + + out := make([]*feeds.Item, 0, len(camps)) + for _, c := range camps { + out = append(out, &feeds.Item{ + Title: c.Subject, + Link: &feeds.Link{Href: c.URL}, + Created: c.CreatedAt.Time, + }) + } + + feed := &feeds.Feed{ + Title: app.constants.SiteName, + Link: &feeds.Link{Href: app.constants.RootURL}, + Description: app.i18n.T("public.archiveTitle"), + Items: out, + } + + if err := feed.WriteRss(c.Response().Writer); err != nil { + app.log.Printf("error generating archive RSS feed: %v", err) + return echo.NewHTTPError(http.StatusBadRequest, app.i18n.T("public.errorProcessingRequest")) + } + + return nil +} + // handleCampaignArchivesPage renders the public campaign archives page. func handleCampaignArchivesPage(c echo.Context) error { var ( diff --git a/cmd/handlers.go b/cmd/handlers.go index ef8a6ef..4b6328c 100644 --- a/cmd/handlers.go +++ b/cmd/handlers.go @@ -194,7 +194,9 @@ func initHTTPHandlers(e *echo.Echo, app *App) { "campUUID", "subUUID"))) e.GET("/campaign/:campUUID/:subUUID/px.png", noIndex(validateUUID(handleRegisterCampaignView, "campUUID", "subUUID"))) + e.GET("/archive", handleCampaignArchivesPage) + e.GET("/archive.xml", handleGetCampaignArchivesFeed) e.GET("/archive/:uuid", handleCampaignArchivePage) e.GET("/public/custom.css", serveCustomApperance("public.custom_css")) diff --git a/go.mod b/go.mod index 188de76..e4534c5 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/fsnotify/fsnotify v1.5.1 // indirect github.com/gofrs/uuid v4.0.0+incompatible github.com/google/uuid v1.3.0 // indirect + github.com/gorilla/feeds v1.1.1 // indirect github.com/huandu/xstrings v1.3.2 // indirect github.com/imdario/mergo v0.3.12 // indirect github.com/jmoiron/sqlx v1.3.4 diff --git a/go.sum b/go.sum index 85a284f..18e5e3b 100644 --- a/go.sum +++ b/go.sum @@ -42,6 +42,8 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gorilla/feeds v1.1.1 h1:HwKXxqzcRNg9to+BbvJog4+f3s/xzvtZXICcQGutYfY= +github.com/gorilla/feeds v1.1.1/go.mod h1:Nk0jZrvPFZX1OBe5NPiddPw7CfwF6Q9eqzaBbaightA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= diff --git a/static/public/static/style.css b/static/public/static/style.css index 372b10d..5075320 100644 --- a/static/public/static/style.css +++ b/static/public/static/style.css @@ -140,7 +140,7 @@ input[disabled] { .archive { list-style-type: none; - margin: 0; + margin: 25px 0 0 0; padding: 0; } .archive .date { @@ -151,6 +151,16 @@ input[disabled] { .archive li { margin-bottom: 15px; } + .feed { + margin-right: 15px; + } + +.home-options { + margin-top: 30px; +} + .home-options a { + margin: 0 7px; + } .pagination { margin-top: 30px; diff --git a/static/public/templates/archive.html b/static/public/templates/archive.html index 0403ac0..3154648 100644 --- a/static/public/templates/archive.html +++ b/static/public/templates/archive.html @@ -17,9 +17,13 @@ {{ end }} {{ if .EnablePublicSubPage }} -

- Subscribe -

+
+ + RSS + + {{ L.T "public.sub" }} +
{{ end }} {{ if gt .Data.TotalPages 1 }} diff --git a/static/public/templates/home.html b/static/public/templates/home.html index 9299421..e72105a 100644 --- a/static/public/templates/home.html +++ b/static/public/templates/home.html @@ -3,6 +3,15 @@
{{ L.T "users.login" }} + +
+ {{ if .EnablePublicSubPage }} + {{ L.T "public.sub" }} + {{ end }} + {{ if .EnablePublicSubPage }} + {{ L.T "public.archiveTitle" }} + {{ end }} +
{{ template "footer" .}} diff --git a/static/public/templates/index.html b/static/public/templates/index.html index 18ac2e0..fe13f5c 100644 --- a/static/public/templates/index.html +++ b/static/public/templates/index.html @@ -6,6 +6,9 @@ {{ .Data.Title }} - {{ .SiteName }} + + +