Make banner link and summary optional

This commit is contained in:
Jason Streifling 2024-10-30 02:12:53 +01:00
parent 0dd2101a08
commit 1fbc0ddcf6
3 changed files with 20 additions and 37 deletions

View File

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

View File

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

View File

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