forked from jason/cpolis
Allow articles to be independent of an issue and allow a title for an issue
This commit is contained in:
@ -73,11 +73,13 @@ func SubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
}
|
||||
|
||||
article := &b.Article{
|
||||
Title: r.PostFormValue("article-title"),
|
||||
Description: r.PostFormValue("article-description"),
|
||||
Published: false,
|
||||
Rejected: false,
|
||||
AuthorID: session.Values["id"].(int64),
|
||||
Title: r.PostFormValue("article-title"),
|
||||
Description: r.PostFormValue("article-description"),
|
||||
Published: false,
|
||||
Rejected: false,
|
||||
AuthorID: session.Values["id"].(int64),
|
||||
IsInIssue: r.PostFormValue("issue") == "on",
|
||||
AutoGenerated: false,
|
||||
}
|
||||
|
||||
article.ID, err = db.AddArticle(article)
|
||||
@ -153,6 +155,7 @@ func ResubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
&b.Attribute{Table: "articles", ID: id, AttName: "title", Value: title},
|
||||
&b.Attribute{Table: "articles", ID: id, AttName: "description", Value: description},
|
||||
&b.Attribute{Table: "articles", ID: id, AttName: "rejected", Value: false},
|
||||
&b.Attribute{Table: "articles", ID: id, AttName: "is_in_issue", Value: r.PostFormValue("issue") == "on"},
|
||||
); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -240,46 +243,27 @@ func ReviewUnpublishedArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.Hand
|
||||
return
|
||||
}
|
||||
|
||||
type htmlData struct {
|
||||
Title string
|
||||
Description string
|
||||
Content template.HTML
|
||||
Tags []*b.Tag
|
||||
ID int64
|
||||
}
|
||||
data := new(struct {
|
||||
Article *b.Article
|
||||
Content template.HTML
|
||||
Tags []*b.Tag
|
||||
})
|
||||
|
||||
var err error
|
||||
data := new(htmlData)
|
||||
|
||||
data.ID, err = strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
article, err := db.GetArticle(data.ID)
|
||||
data.Article, err = db.GetArticle(id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
data.Title, err = b.ConvertToPlain(article.Title)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
data.Description, err = b.ConvertToPlain(article.Description)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
articleAbsName := fmt.Sprint(c.ArticleDir, "/", article.ID, ".md")
|
||||
articleAbsName := fmt.Sprint(c.ArticleDir, "/", data.Article.ID, ".md")
|
||||
contentBytes, err := os.ReadFile(articleAbsName)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
@ -295,7 +279,7 @@ func ReviewUnpublishedArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.Hand
|
||||
}
|
||||
data.Content = template.HTML(content)
|
||||
|
||||
data.Tags, err = db.GetArticleTags(data.ID)
|
||||
data.Tags, err = db.GetArticleTags(data.Article.ID)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -314,13 +298,12 @@ func ReviewRejectedArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.Handler
|
||||
return
|
||||
}
|
||||
|
||||
type htmlData struct {
|
||||
data := new(struct {
|
||||
Selected map[int64]bool
|
||||
Article *b.Article
|
||||
Content string
|
||||
Tags []*b.Tag
|
||||
}
|
||||
data := new(htmlData)
|
||||
})
|
||||
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
@ -378,13 +361,20 @@ func PublishArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
}
|
||||
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
article, err := db.GetArticle(id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err = db.AddArticleToCurrentIssue(id); err != nil {
|
||||
if err = db.AddArticleToCurrentIssue(article.ID); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -523,7 +513,7 @@ func ShowPublishedArticles(c *b.Config, db *b.DB, s *b.CookieStore) http.Handler
|
||||
|
||||
filteredArticles := make([]*b.Article, 0)
|
||||
for _, article := range publishedArticles {
|
||||
if article.Title != "Autogenerated cpolis Issue Article" {
|
||||
if !article.AutoGenerated {
|
||||
filteredArticles = append(filteredArticles, article)
|
||||
}
|
||||
}
|
||||
|
@ -59,14 +59,15 @@ func PublishLatestIssue(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFun
|
||||
mimeType := mime.TypeByExtension(filepath.Ext(imgAbsName))
|
||||
|
||||
article := &b.Article{
|
||||
Title: "Autogenerated cpolis Issue Article",
|
||||
EncURL: fmt.Sprint(c.Domain, "/image/serve/", imgFileName),
|
||||
EncLength: int(imgSize),
|
||||
EncType: mimeType,
|
||||
Published: true,
|
||||
Rejected: false,
|
||||
Created: time.Now(),
|
||||
AuthorID: session.Values["id"].(int64),
|
||||
Title: r.PostFormValue("issue-title"),
|
||||
EncURL: fmt.Sprint(c.Domain, "/image/serve/", imgFileName),
|
||||
EncLength: int(imgSize),
|
||||
EncType: mimeType,
|
||||
Published: true,
|
||||
Rejected: false,
|
||||
Created: time.Now(),
|
||||
AuthorID: session.Values["id"].(int64),
|
||||
AutoGenerated: true,
|
||||
}
|
||||
fmt.Println(article.Link)
|
||||
|
||||
|
Reference in New Issue
Block a user