From b01048449354c53c79313d4dddcfa3e2b223f014 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Thu, 20 May 2021 20:44:59 -0400 Subject: [PATCH 1/3] Return `url` of new post on publish --- posts.go | 4 +++- read.go | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/posts.go b/posts.go index 107f0c1..ac2144c 100644 --- a/posts.go +++ b/posts.go @@ -125,6 +125,7 @@ type ( Views int64 `json:"views"` Owner *PublicUser `json:"-"` IsOwner bool `json:"-"` + URL string `json:"url,omitempty"` Collection *CollectionObj `json:"collection,omitempty"` } @@ -612,6 +613,7 @@ func newPost(app *App, w http.ResponseWriter, r *http.Request) error { newPost.extractData() newPost.OwnerName = username + newPost.URL = newPost.CanonicalURL(app.cfg.App.Host) // Write success now response := impart.WriteSuccess(w, newPost, http.StatusCreated) @@ -1124,7 +1126,7 @@ func (p *Post) processPost() PublicPost { func (p *PublicPost) CanonicalURL(hostName string) string { if p.Collection == nil || p.Collection.Alias == "" { - return hostName + "/" + p.ID + return hostName + "/" + p.ID + ".md" } return p.Collection.CanonicalURL() + p.Slug.String } diff --git a/read.go b/read.go index b11e657..7fb700e 100644 --- a/read.go +++ b/read.go @@ -315,7 +315,6 @@ func viewLocalTimelineFeed(app *App, w http.ResponseWriter, req *http.Request) e author = p.Collection.Title } else { author = "Anonymous" - permalink += ".md" } i := &Item{ Id: app.cfg.App.Host + "/read/a/" + p.ID, From 2938bba15a8ca70c26f716fda5239149df4cf542 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 25 May 2021 16:58:09 -0400 Subject: [PATCH 2/3] Support updating collection only with monetization_pointer --- database.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/database.go b/database.go index df300ce..e8cac92 100644 --- a/database.go +++ b/database.go @@ -875,7 +875,7 @@ func (db *datastore) UpdateCollection(c *SubmittedCollection, alias string) erro // WHERE values q.Where("alias = ? AND owner_id = ?", alias, c.OwnerID) - if q.Updates == "" { + if q.Updates == "" && c.Monetization == nil { return ErrPostNoUpdatableVals } @@ -932,10 +932,12 @@ func (db *datastore) UpdateCollection(c *SubmittedCollection, alias string) erro } // Update rest of the collection data - res, err = db.Exec("UPDATE collections SET "+q.Updates+" WHERE "+q.Conditions, q.Params...) - if err != nil { - log.Error("Unable to update collection: %v", err) - return err + if q.Updates != "" { + res, err = db.Exec("UPDATE collections SET "+q.Updates+" WHERE "+q.Conditions, q.Params...) + if err != nil { + log.Error("Unable to update collection: %v", err) + return err + } } rowsAffected, _ = res.RowsAffected() From 6740fbe0975ed4496e702a0a93693e866fbd59c8 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 25 May 2021 17:04:17 -0400 Subject: [PATCH 3/3] Support publishing title-only posts --- pad.go | 4 +++- posts.go | 26 ++++++++++++++++++++++---- templates/classic.tmpl | 2 +- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/pad.go b/pad.go index b64c282..d150334 100644 --- a/pad.go +++ b/pad.go @@ -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 diff --git a/posts.go b/posts.go index ac2144c..f60c3af 100644 --- a/posts.go +++ b/posts.go @@ -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, } } diff --git a/templates/classic.tmpl b/templates/classic.tmpl index 42a6bce..ecc8cb9 100644 --- a/templates/classic.tmpl +++ b/templates/classic.tmpl @@ -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);