From 2082e50194df034ae2b6268d671997624608cacf Mon Sep 17 00:00:00 2001 From: movsb Date: Tue, 18 Jun 2024 03:35:27 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9C=8B=E8=B5=B7=E6=9D=A5=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E9=98=85=E8=AF=BB=E5=99=A8=E6=B2=A1=E6=9C=89=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=90=8E=E7=9A=84=E5=86=85=E5=AE=B9=EF=BC=88?= =?UTF-8?q?=E4=B8=8D=E7=A1=AE=E5=AE=9A=E4=BF=AE=E5=A4=8D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- theme/modules/rss/rss.go | 22 ++++++++++++++++------ theme/modules/rss/rss.xml | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/theme/modules/rss/rss.go b/theme/modules/rss/rss.go index 57f72dbf..4129d84d 100644 --- a/theme/modules/rss/rss.go +++ b/theme/modules/rss/rss.go @@ -23,10 +23,16 @@ var tmpl string // Article ... type Article struct { *proto.Post - Date string + Date Date Content template.HTML } +type Date int + +func (d Date) String() string { + return time.Unix(int64(d), 0).Local().Format(time.RFC1123) +} + // RSS ... type RSS struct { config _Config @@ -36,6 +42,8 @@ type RSS struct { Home string Articles []*Article + LastBuildDate Date + tmpl *template.Template svc proto.TaoBlogServer } @@ -61,10 +69,12 @@ func New(svc proto.TaoBlogServer, options ...Option) *RSS { articleCount: 10, }, - Name: info.Name, - Description: info.Description, - Home: info.Home, - svc: svc, + Name: info.Name, + Description: info.Description, + Home: info.Home, + LastBuildDate: Date(info.LastPostedAt), + + svc: svc, } for _, opt := range options { @@ -93,7 +103,7 @@ func (r *RSS) ServeHTTP(w http.ResponseWriter, req *http.Request) { for _, article := range rsp.Posts { rssArticle := Article{ Post: article, - Date: time.Unix(int64(article.Date), 0).Local().Format(time.RFC1123), + Date: Date(article.Date), Content: template.HTML(cdata(article.Content)), } rssArticles = append(rssArticles, &rssArticle) diff --git a/theme/modules/rss/rss.xml b/theme/modules/rss/rss.xml index 73095443..6bd2684b 100644 --- a/theme/modules/rss/rss.xml +++ b/theme/modules/rss/rss.xml @@ -3,6 +3,7 @@ {{ .Name }} {{ .Home }} {{ .Description }} + {{ .LastBuildDate }} {{- range .Articles }} {{ .Title }}