aboutsummaryrefslogtreecommitdiffstats
path: root/internal/store/posts.go
diff options
context:
space:
mode:
authorgrm <grm@eyesin.space>2026-09-14 22:58:08 +0300
committergrm <grm@eyesin.space>2026-09-14 22:58:08 +0300
commit5f9fc2a8667a9438b6336d75026f9a455fc9c4ce (patch)
tree8fa0009b2487e35219bfdbb34f9802704007076e /internal/store/posts.go
parente14a4250efb828262347f5a4bbc4067cd71d885f (diff)
downloadblogspace-5f9fc2a8667a9438b6336d75026f9a455fc9c4ce.tar.gz
blogspace-5f9fc2a8667a9438b6336d75026f9a455fc9c4ce.tar.bz2
blogspace-5f9fc2a8667a9438b6336d75026f9a455fc9c4ce.zip
Let the blogger set a post's date, when writing it and afterwards
The post date is posts.created_at: it already drives ordering, the archive, the feed and the displayed dates, so making it editable is a form field rather than a new column. The datetime-local input degrades to a text box on old browsers, so the server also accepts the value typed by hand; blank keeps the current date. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sd8UPWrvyYCLj97JexNw3A
Diffstat (limited to 'internal/store/posts.go')
-rw-r--r--internal/store/posts.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/internal/store/posts.go b/internal/store/posts.go
index 94bc856..569640b 100644
--- a/internal/store/posts.go
+++ b/internal/store/posts.go
@@ -108,10 +108,15 @@ func (bs *BlogStore) PublishedPostBySlug(ctx context.Context, pageID int64, slug
WHERE p.page_id=$1 AND p.slug=$2 AND p.published`, pageID, slug))
}
+// CreatePost inserts the post; a zero CreatedAt means now. The post date is
+// the blogger's to choose, so it is a plain column rather than a fixed stamp.
func (bs *BlogStore) CreatePost(ctx context.Context, p *Post) (*Post, error) {
+ if p.CreatedAt.IsZero() {
+ p.CreatedAt = time.Now()
+ }
var id int64
- err := bs.db.QueryRow(ctx, `INSERT INTO posts (page_id, slug, title, body_md, body_html, published) VALUES ($1,$2,$3,$4,$5,$6) RETURNING id`,
- p.PageID, p.Slug, p.Title, p.BodyMD, p.BodyHTML, p.Published).Scan(&id)
+ err := bs.db.QueryRow(ctx, `INSERT INTO posts (page_id, slug, title, body_md, body_html, published, created_at) VALUES ($1,$2,$3,$4,$5,$6,$7) RETURNING id`,
+ p.PageID, p.Slug, p.Title, p.BodyMD, p.BodyHTML, p.Published, p.CreatedAt).Scan(&id)
if err != nil {
return nil, wrap(err)
}
@@ -119,8 +124,8 @@ func (bs *BlogStore) CreatePost(ctx context.Context, p *Post) (*Post, error) {
}
func (bs *BlogStore) UpdatePost(ctx context.Context, p *Post) error {
- _, err := bs.db.Exec(ctx, `UPDATE posts SET page_id=$2, slug=$3, title=$4, body_md=$5, body_html=$6, published=$7, updated_at=now() WHERE id=$1`,
- p.ID, p.PageID, p.Slug, p.Title, p.BodyMD, p.BodyHTML, p.Published)
+ _, err := bs.db.Exec(ctx, `UPDATE posts SET page_id=$2, slug=$3, title=$4, body_md=$5, body_html=$6, published=$7, created_at=$8, updated_at=now() WHERE id=$1`,
+ p.ID, p.PageID, p.Slug, p.Title, p.BodyMD, p.BodyHTML, p.Published, p.CreatedAt)
return wrap(err)
}