Support publishing title-only posts

This commit is contained in:
Matt Baer 2021-05-25 17:04:17 -04:00
parent 2938bba15a
commit 6740fbe097
3 changed files with 26 additions and 6 deletions

4
pad.go
View file

@ -90,6 +90,7 @@ func handleViewPad(app *App, w http.ResponseWriter, r *http.Request) error {
}
appData.EditCollection, err = app.db.GetCollectionForPad(collAlias)
if err != nil {
log.Error("Unable to GetCollectionForPad: %s", err)
return err
}
appData.EditCollection.hostName = app.cfg.App.Host
@ -101,9 +102,10 @@ func handleViewPad(app *App, w http.ResponseWriter, r *http.Request) error {
if appData.Post.Gone {
return ErrPostUnpublished
} else if appData.Post.Found && appData.Post.Content != "" {
} else if appData.Post.Found && (appData.Post.Title != "" || appData.Post.Content != "") {
// Got the post
} else if appData.Post.Found {
log.Error("Found post, but other conditions failed.")
return ErrPostFetchError
} else {
return ErrPostNotFound

View file

@ -397,7 +397,7 @@ func handleViewPost(app *App, w http.ResponseWriter, r *http.Request) error {
}
// Check if post has been unpublished
if content == "" {
if title == "" && content == "" {
gone = true
if isJSON {
@ -546,9 +546,14 @@ func newPost(app *App, w http.ResponseWriter, r *http.Request) error {
t := ""
p.Title = &t
}
if strings.TrimSpace(*(p.Content)) == "" {
if strings.TrimSpace(*(p.Title)) == "" && (p.Content == nil || strings.TrimSpace(*(p.Content)) == "") {
return ErrNoPublishableContent
}
if p.Content == nil {
c := ""
p.Content = &c
}
} else {
post := r.FormValue("body")
appearance := r.FormValue("font")
@ -1260,10 +1265,22 @@ func getRawPost(app *App, friendlyID string) *RawPost {
case err == sql.ErrNoRows:
return &RawPost{Content: "", Found: false, Gone: false}
case err != nil:
log.Error("Unable to fetch getRawPost: %s", err)
return &RawPost{Content: "", Found: true, Gone: false}
}
return &RawPost{Title: title, Content: content, Font: font, Created: created, Updated: updated, IsRTL: isRTL, Language: lang, OwnerID: ownerID.Int64, Found: true, Gone: content == ""}
return &RawPost{
Title: title,
Content: content,
Font: font,
Created: created,
Updated: updated,
IsRTL: isRTL,
Language: lang,
OwnerID: ownerID.Int64,
Found: true,
Gone: content == "" && title == "",
}
}
@ -1286,6 +1303,7 @@ func getRawCollectionPost(app *App, slug, collAlias string) *RawPost {
case err == sql.ErrNoRows:
return &RawPost{Content: "", Found: false, Gone: false}
case err != nil:
log.Error("Unable to fetch getRawCollectionPost: %s", err)
return &RawPost{Content: "", Found: true, Gone: false}
}
@ -1301,7 +1319,7 @@ func getRawCollectionPost(app *App, slug, collAlias string) *RawPost {
Language: lang,
OwnerID: ownerID.Int64,
Found: true,
Gone: content == "",
Gone: content == "" && title == "",
Views: views,
}
}

View file

@ -283,7 +283,7 @@
*/
$btnPublish.on('click', function(e) {
e.preventDefault();
if (!publishing && $content.el.value) {
if (!publishing && ($title.el.value || $content.el.value)) {
var title = $title.el.value;
var content = $content.el.value;
publish(title, content, selectedFont);