Added Tags to RSS feed as categories

This commit is contained in:
Jason Streifling 2024-03-05 18:20:34 +01:00
parent a9c61c5a11
commit 4aa4fff5e8
6 changed files with 18 additions and 7 deletions

View File

@ -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()

View File

@ -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),
},
}
}

View File

@ -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")

2
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

View File

@ -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()
}