From 4680e2e046c7d70839ca97eaaa72fa8cf17b91d6 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 29 Mar 2022 13:23:20 -0400 Subject: [PATCH] Show post excerpt in stats list when no post title Originally requested on the forum: https://discuss.write.as/t/use-non-random-ids-for-untitled-posts-in-blog-stats/5046 --- database.go | 4 ++-- templates/user/stats.tmpl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/database.go b/database.go index f474ae9..8e96e42 100644 --- a/database.go +++ b/database.go @@ -1774,7 +1774,7 @@ func (db *datastore) GetTopPosts(u *User, alias string, hostName string) (*[]Pub where = " AND alias = ?" params = append(params, alias) } - rows, err := db.Query("SELECT p.id, p.slug, p.view_count, p.title, c.alias, c.title, c.description, c.view_count FROM posts p LEFT JOIN collections c ON p.collection_id = c.id WHERE p.owner_id = ?"+where+" ORDER BY p.view_count DESC, created DESC LIMIT 25", params...) + rows, err := db.Query("SELECT p.id, p.slug, p.view_count, p.title, p.content, c.alias, c.title, c.description, c.view_count FROM posts p LEFT JOIN collections c ON p.collection_id = c.id WHERE p.owner_id = ?"+where+" ORDER BY p.view_count DESC, created DESC LIMIT 25", params...) if err != nil { log.Error("Failed selecting from posts: %v", err) return nil, impart.HTTPError{http.StatusInternalServerError, "Couldn't retrieve user top posts."} @@ -1788,7 +1788,7 @@ func (db *datastore) GetTopPosts(u *User, alias string, hostName string) (*[]Pub c := Collection{} var alias, title, description sql.NullString var views sql.NullInt64 - err = rows.Scan(&p.ID, &p.Slug, &p.ViewCount, &p.Title, &alias, &title, &description, &views) + err = rows.Scan(&p.ID, &p.Slug, &p.ViewCount, &p.Title, &p.Content, &alias, &title, &description, &views) if err != nil { log.Error("Failed scanning User.getPosts() row: %v", err) gotErr = true diff --git a/templates/user/stats.tmpl b/templates/user/stats.tmpl index f3e3dce..0791f77 100644 --- a/templates/user/stats.tmpl +++ b/templates/user/stats.tmpl @@ -51,7 +51,7 @@ td.none { Total Views {{range .TopPosts}} - {{if ne .Title.String ""}}{{.Title.String}}{{else}}{{.ID}}{{end}} + {{if ne .DisplayTitle ""}}{{.DisplayTitle}}{{else}}{{.ID}}{{end}} {{ if not $.Collection }}{{if .Collection}}{{.Collection.Title}}{{else}}Draft{{end}}{{ end }} {{.ViewCount}} {{end}}