repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
68db7f1
parent
184a78b
author
Eric Bower
date
2023-02-28 05:19:30 +0000 UTC
feat(cms): ability to see view count for posts
1 files changed,  +26, -19
M wish/cms/ui/posts/post_view.go
+26, -19
 1@@ -9,30 +9,34 @@ import (
 2 )
 3 
 4 type styledKey struct {
 5-	styles    common.Styles
 6-	date      string
 7-	gutter    string
 8-	postLabel string
 9-	dateLabel string
10-	dateVal   string
11-	title     string
12-	urlLabel  string
13-	url       string
14+	styles     common.Styles
15+	date       string
16+	gutter     string
17+	postLabel  string
18+	dateLabel  string
19+	dateVal    string
20+	title      string
21+	urlLabel   string
22+	url        string
23+	views      int
24+	viewsLabel string
25 }
26 
27 func (m Model) newStyledKey(styles common.Styles, post *db.Post, urls config.ConfigURL) styledKey {
28 	publishAt := post.PublishAt
29 	// Default state
30 	return styledKey{
31-		styles:    styles,
32-		gutter:    " ",
33-		postLabel: "post:",
34-		date:      publishAt.String(),
35-		dateLabel: "publish_at:",
36-		dateVal:   styles.LabelDim.Render(publishAt.Format("02 Jan, 2006")),
37-		title:     post.Title,
38-		urlLabel:  "url:",
39-		url:       urls.PostURL(post.Username, post.Slug),
40+		styles:     styles,
41+		gutter:     " ",
42+		postLabel:  "post:",
43+		date:       publishAt.String(),
44+		dateLabel:  "publish_at:",
45+		dateVal:    styles.LabelDim.Render(publishAt.Format("02 Jan, 2006")),
46+		title:      post.Title,
47+		urlLabel:   "url:",
48+		url:        urls.PostURL(post.Username, post.Slug),
49+		viewsLabel: "views:",
50+		views:      post.Views,
51 	}
52 }
53 
54@@ -41,6 +45,7 @@ func (k *styledKey) selected() {
55 	k.gutter = common.VerticalLine(common.StateSelected)
56 	k.postLabel = k.styles.Label.Render("post:")
57 	k.dateLabel = k.styles.Label.Render("publish_at:")
58+	k.viewsLabel = k.styles.Label.Render("views:")
59 	k.urlLabel = k.styles.Label.Render("url:")
60 }
61 
62@@ -50,6 +55,7 @@ func (k *styledKey) deleting() {
63 	k.postLabel = k.styles.Delete.Render("post:")
64 	k.dateLabel = k.styles.Delete.Render("publish_at:")
65 	k.urlLabel = k.styles.Delete.Render("url:")
66+	k.viewsLabel = k.styles.Delete.Render("views:")
67 	k.title = k.styles.DeleteDim.Render(k.title)
68 }
69 
70@@ -61,9 +67,10 @@ func (k styledKey) render(state postState) string {
71 		k.deleting()
72 	}
73 	return fmt.Sprintf(
74-		"%s %s %s\n%s %s %s\n%s %s %s\n\n",
75+		"%s %s %s\n%s %s %s\n%s %s %d\n%s %s %s\n\n",
76 		k.gutter, k.postLabel, k.title,
77 		k.gutter, k.dateLabel, k.dateVal,
78+		k.gutter, k.viewsLabel, k.views,
79 		k.gutter, k.urlLabel, k.url,
80 	)
81 }