High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.
JavaScript campaigncampaign-managementemail-marketingemail-subscriptionlistmonkmailing-listnewsletternewsletter-managementnewsletter-softwareself-hostedsms-gatewaysmtptransactional-emails
Add RSS feed to the public mailing list archive.
Kailash Nadhf958f3d24b85
diff --git a/cmd/archive.go b/cmd/archive.goindex d2fdf75e..197f79a0 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.goindex ef8a6ef8..4b6328c5 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.modindex 188de760..e4534c51 100644--- a/go.mod+++ b/go.mod@@ -9,6 +9,7 @@ require (github.com/fsnotify/fsnotify v1.5.1 // indirectgithub.com/gofrs/uuid v4.0.0+incompatiblegithub.com/google/uuid v1.3.0 // indirect+ github.com/gorilla/feeds v1.1.1 // indirectgithub.com/huandu/xstrings v1.3.2 // indirectgithub.com/imdario/mergo v0.3.12 // indirectgithub.com/jmoiron/sqlx v1.3.4diff --git a/go.sum b/go.sumindex 85a284f3..18e5e3b3 100644--- a/go.sum+++ b/go.sum@@ -42,6 +42,8 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5agithub.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.cssindex 372b10de..5075320e 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.htmlindex 0403ac03..31546488 100644--- a/static/public/templates/archive.html+++ b/static/public/templates/archive.html@@ -17,9 +17,13 @@{{ end }}{{ if .EnablePublicSubPage }}- <p class="right">- <a href="{{ .RootURL }}/subscription/form">Subscribe</a>- </p>+ <div class="right">+ <a href="{{ .RootURL }}/archive.xml">+ <img src="{{ .RootURL }}/public/static/rss.svg" alt="RSS" class="feed"+ width="16" height="16" />+ </a>+ <a href="{{ .RootURL }}/subscription/form">{{ L.T "public.sub" }}</a>+ </div>{{ end }}{{ if gt .Data.TotalPages 1 }}diff --git a/static/public/templates/home.html b/static/public/templates/home.htmlindex 92994216..e72105a8 100644--- a/static/public/templates/home.html+++ b/static/public/templates/home.html@@ -3,6 +3,15 @@<section class="center"><a href="admin" class="button">{{ L.T "users.login" }}</a>++ <div class="home-options">+ {{ if .EnablePublicSubPage }}+ <a href="{{ .RootURL }}/subscription/form">{{ L.T "public.sub" }}</a>+ {{ end }}+ {{ if .EnablePublicSubPage }}+ <a href="{{ .RootURL }}/archive">{{ L.T "public.archiveTitle" }}</a>+ {{ end }}+ </div></section>{{ template "footer" .}}diff --git a/static/public/templates/index.html b/static/public/templates/index.htmlindex 18ac2e04..fe13f5cf 100644--- a/static/public/templates/index.html+++ b/static/public/templates/index.html@@ -6,6 +6,9 @@<title>{{ .Data.Title }} - {{ .SiteName }}</title><meta name="description" content="{{ .Data.Description }}" /><meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />++ <link rel="alternate" type="application/rss+xml" title="{{ L.T "public.archiveTitle" }} - {{ .SiteName }}" href="{{ .RootURL }}/archive.xml" />+<link href="/public/static/style.css" rel="stylesheet" type="text/css" /><link href="/public/custom.css" rel="stylesheet" type="text/css"><script src="/public/custom.js" async defer></script>