From 4aa4fff5e844e237aaab94ee3636ae15e4694502 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Tue, 5 Mar 2024 18:20:34 +0100 Subject: [PATCH] Added Tags to RSS feed as categories --- cmd/data/articles.go | 10 ++++++---- cmd/data/rss.go | 3 +++ cmd/ui/articles.go | 6 +++++- go.mod | 2 +- go.sum | 2 ++ main.go | 2 +- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cmd/data/articles.go b/cmd/data/articles.go index e00eabd..df28c25 100644 --- a/cmd/data/articles.go +++ b/cmd/data/articles.go @@ -21,15 +21,17 @@ type Article struct { AuthorID int64 } +// TODO: setCh type ArticleList struct { addCh chan *Article delCh chan uuid.UUID - retCh chan *Article getCh chan []Article + retCh chan *Article articles []*Article wg sync.WaitGroup } +// TODO: setCh type TagList struct { addCh chan string getCh chan []string @@ -41,8 +43,8 @@ func initArticleList() *ArticleList { return &ArticleList{ addCh: make(chan *Article), delCh: make(chan uuid.UUID), - retCh: make(chan *Article), getCh: make(chan []Article), + retCh: make(chan *Article), } } @@ -90,7 +92,7 @@ func (tl *TagList) start() { func NewArticleList() *ArticleList { list := initArticleList() - list.articles = []*Article{} + list.articles = make([]*Article, 0) list.wg.Add(1) go list.start() @@ -148,7 +150,7 @@ func LoadArticleList(filename string) (*ArticleList, error) { func NewTagList() *TagList { list := initTagList() - list.tags = []string{} + list.tags = make([]string, 0) list.wg.Add(1) go list.start() diff --git a/cmd/data/rss.go b/cmd/data/rss.go index c588b64..875e267 100644 --- a/cmd/data/rss.go +++ b/cmd/data/rss.go @@ -22,6 +22,9 @@ func initChannel() *Channel { addCh: make(chan *rss.Item), setCh: make(chan rss.Channel), getCh: make(chan rss.Channel), + channel: rss.Channel{ + Items: make([]*rss.Item, 0), + }, } } diff --git a/cmd/ui/articles.go b/cmd/ui/articles.go index 811f145..0f4c6cc 100644 --- a/cmd/ui/articles.go +++ b/cmd/ui/articles.go @@ -58,6 +58,9 @@ func FinishArticle(al *data.ArticleList, s *data.CookieStore) http.HandlerFunc { return } + r.ParseForm() + article.Tags = append(article.Tags, r.Form["tags"]...) + session, err := s.Get(r, "cookie") if err != nil { tmpl, err := template.ParseFiles("web/templates/login.html") @@ -71,7 +74,7 @@ func FinishArticle(al *data.ArticleList, s *data.CookieStore) http.HandlerFunc { article.AuthorID = session.Values["id"].(int64) al.Add(article) - al.Save("tmp/articles.gob") + al.Save("tmp/unpublished-articles.gob") tmpl, err := template.ParseFiles("web/templates/hub.html") tmpl = template.Must(tmpl, err) @@ -147,6 +150,7 @@ func PublishArticle(c *data.Channel, al *data.ArticleList, s *data.CookieStore) PubDate: article.Created.Format(time.RFC1123Z), Description: article.Desc, Content: &rss.Content{Value: article.Content}, + Categories: article.Tags, }) c.Save("tmp/rss.gob") diff --git a/go.mod b/go.mod index ac45c33..184b8a6 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module streifling.com/jason/cpolis go 1.22.0 require ( - git.streifling.com/jason/rss v0.0.0-20240305160829-6cd08bb65d2a + git.streifling.com/jason/rss v0.0.0-20240305164907-524bf9676188 github.com/go-sql-driver/mysql v1.7.1 github.com/google/uuid v1.6.0 github.com/gorilla/feeds v1.1.2 diff --git a/go.sum b/go.sum index 4422e72..13ec948 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ git.streifling.com/jason/rss v0.0.0-20240305160544-c8551159fe32 h1:G25NZzsD73rOk git.streifling.com/jason/rss v0.0.0-20240305160544-c8551159fe32/go.mod h1:gpZF0nZbQSstMpyHD9DTAvlQEG7v4pjO5c7aIMWM4Jg= git.streifling.com/jason/rss v0.0.0-20240305160829-6cd08bb65d2a h1:TWQ9gwe7eWjaLUrZ0CJSc+sUUOw3VoGHlR3F8mH6vqs= git.streifling.com/jason/rss v0.0.0-20240305160829-6cd08bb65d2a/go.mod h1:gpZF0nZbQSstMpyHD9DTAvlQEG7v4pjO5c7aIMWM4Jg= +git.streifling.com/jason/rss v0.0.0-20240305164907-524bf9676188 h1:C8M/j3f+cl5Y7YfGpU/ynb/SC/4tTYMDsyGFt3rswM8= +git.streifling.com/jason/rss v0.0.0-20240305164907-524bf9676188/go.mod h1:gpZF0nZbQSstMpyHD9DTAvlQEG7v4pjO5c7aIMWM4Jg= github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= diff --git a/main.go b/main.go index 16d2dfe..51694d9 100644 --- a/main.go +++ b/main.go @@ -47,7 +47,7 @@ func main() { } store := data.NewCookieStore(key) - articleList, err := data.LoadArticleList("tmp/articles.gob") + articleList, err := data.LoadArticleList("tmp/unpublished-articles.gob") if err != nil { articleList = data.NewArticleList() }