From 1fbc0ddcf6662864fa57d60d3c805abfd0d69d8c Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Wed, 30 Oct 2024 02:12:53 +0100 Subject: [PATCH] Make banner link and summary optional --- cmd/backend/atom.go | 30 +++++++++++++++++------------- cmd/frontend/articles.go | 23 +++-------------------- cmd/frontend/issues.go | 4 ---- 3 files changed, 20 insertions(+), 37 deletions(-) diff --git a/cmd/backend/atom.go b/cmd/backend/atom.go index f969f32..8ce4fe0 100644 --- a/cmd/backend/atom.go +++ b/cmd/backend/atom.go @@ -30,12 +30,25 @@ func GenerateAtomFeed(c *Config, db *DB) (*string, error) { } entry := atom.NewEntry(articleTitle) entry.ID = atom.NewID(fmt.Sprint("urn:entry:", article.ID)) - entry.Content = atom.NewContent(atom.OutOfLine, "text/hmtl", article.ContentLink) entry.Published = atom.NewDate(article.Created) - linkID := entry.AddLink(atom.NewLink(article.BannerLink)) - entry.Links[linkID].Rel = "enclosure" - entry.Links[linkID].Type = "image/webp" + if article.AutoGenerated { + entry.Content = atom.NewContent(atom.InlineText, "text", "") + } else { + entry.Content = atom.NewContent(atom.OutOfLine, "text/hmtl", article.ContentLink) + + articleSummary, err := ConvertToPlain(article.Summary) + if err != nil { + return nil, fmt.Errorf("error converting description to plain text for Atom feed: %v", err) + } + entry.Summary = atom.NewText("text", articleSummary) + } + + if len(article.BannerLink) > 0 { + linkID := entry.AddLink(atom.NewLink(article.BannerLink)) + entry.Links[linkID].Rel = "enclosure" + entry.Links[linkID].Type = "image/webp" + } user, err := db.GetUser(c, article.AuthorID) if err != nil { @@ -43,15 +56,6 @@ func GenerateAtomFeed(c *Config, db *DB) (*string, error) { } entry.AddAuthor(atom.NewPerson(user.FirstName + " " + user.LastName)) - articleSummary, err := ConvertToPlain(article.Summary) - if err != nil { - return nil, fmt.Errorf("error converting description to plain text for Atom feed: %v", err) - } - if article.AutoGenerated { - articleSummary = "auto generated" - } - entry.Summary = atom.NewText("text", articleSummary) - tags, err := db.GetArticleTags(article.ID) if err != nil { return nil, fmt.Errorf("error getting tags for articles for Atom feed: %v", err) diff --git a/cmd/frontend/articles.go b/cmd/frontend/articles.go index 806c7ae..816480d 100644 --- a/cmd/frontend/articles.go +++ b/cmd/frontend/articles.go @@ -80,7 +80,7 @@ func SubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { article := &b.Article{ Title: r.PostFormValue("article-title"), - BannerLink: r.PostFormValue("article-banner-url"), + BannerLink: c.Domain + "/image/serve/" + r.PostFormValue("article-banner-url"), Summary: r.PostFormValue("article-summary"), Published: false, Rejected: false, @@ -94,17 +94,6 @@ func SubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return } - if len(article.BannerLink) == 0 { - http.Error(w, "Bitte ein Titelbild einfügen.", http.StatusBadRequest) - return - } - article.BannerLink = c.Domain + "/image/serve/" + article.BannerLink - - if len(article.Summary) == 0 { - http.Error(w, "Bitte die Beschreibung eingeben.", http.StatusBadRequest) - return - } - article.ID, err = db.AddArticle(article) if err != nil { log.Println(err) @@ -185,17 +174,11 @@ func ResubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { } bannerLink := r.PostFormValue("article-banner-url") - if len(bannerLink) == 0 { - http.Error(w, "Bitte ein Titelbild einfügen.", http.StatusBadRequest) - return + if len(bannerLink) != 0 { + bannerLink = c.Domain + "/image/serve/" + bannerLink } - bannerLink = c.Domain + "/image/serve/" + bannerLink summary := r.PostFormValue("article-summary") - if len(summary) == 0 { - http.Error(w, "Bitte die Beschreibung eingeben.", http.StatusBadRequest) - return - } content := r.PostFormValue("article-content") if len(content) == 0 { diff --git a/cmd/frontend/issues.go b/cmd/frontend/issues.go index 4aefb63..d290681 100644 --- a/cmd/frontend/issues.go +++ b/cmd/frontend/issues.go @@ -41,10 +41,6 @@ func PublishLatestIssue(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFun http.Error(w, "Bitte den Titel eingeben.", http.StatusBadRequest) return } - if len(article.BannerLink) == 0 { - http.Error(w, "Bitte ein Titelbild einfügen.", http.StatusBadRequest) - return - } article.ID, err = db.AddArticle(article) if err != nil {