summaryrefslogtreecommitdiff
path: root/srv
diff options
context:
space:
mode:
Diffstat (limited to 'srv')
-rw-r--r--srv/src/api/render.go2
-rw-r--r--srv/src/api/tpl/index.html48
-rw-r--r--srv/src/post/post.go17
-rw-r--r--srv/src/post/post_test.go2
4 files changed, 37 insertions, 32 deletions
diff --git a/srv/src/api/render.go b/srv/src/api/render.go
index 6359505..cacdb26 100644
--- a/srv/src/api/render.go
+++ b/srv/src/api/render.go
@@ -42,7 +42,7 @@ func mustParseTpl(name string) *template.Template {
func (a *api) renderIndexHandler() http.Handler {
tpl := mustParseTpl("index.html")
- const pageCount = 20
+ const pageCount = 10
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
diff --git a/srv/src/api/tpl/index.html b/srv/src/api/tpl/index.html
index b71dc01..1858ea8 100644
--- a/srv/src/api/tpl/index.html
+++ b/srv/src/api/tpl/index.html
@@ -1,28 +1,36 @@
{{ define "body" }}
-<ul id="posts-list">
-
- {{ range .Posts }}
- <li>
- <h2>
- <a href="{{ .HTTPPath }}">{{ .Title }}</a>
- </h2>
- <span>{{ .PublishedAt.Format "2006-01-02" }}</span>
- {{ if not .LastUpdatedAt.IsZero }}
- <span>(Updated {{ .LastUpdatedAt.Format "2006-01-02" }})</span>
+
+ <ul id="posts-list">
+
+ {{ range .Posts }}
+ <li>
+ <h2>
+ <a href="posts/{{ .HTTPPath }}">{{ .Title }}</a>
+ </h2>
+ <span>{{ .PublishedAt.Format "2006-01-02" }}</span>
+ {{ if not .LastUpdatedAt.IsZero }}
+ <span>(Updated {{ .LastUpdatedAt.Format "2006-01-02" }})</span>
+ {{ end }}
+ <p>{{ .Description }}</p>
+ </li>
{{ end }}
- <p>{{ .Description }}</p>
- </li>
- {{ end }}
-</ul>
-{{ end }}
+ </ul>
-{{ if ge .PrevPage 0 }}
-<a href="?p={{ .PrevPage}}">Previous</a>
-{{ end }}
+ {{ if or (ge .PrevPage 0) (ge .NextPage 0) }}
+ <div id="page-turner">
+
+ {{ if ge .PrevPage 0 }}
+ <a style="float: left;" href="?p={{ .PrevPage}}">Newer</a>
+ {{ end }}
+
+ {{ if ge .NextPage 0 }}
+ <a style="float:right;" href="?p={{ .NextPage}}">Older</a>
+ {{ end }}
+
+ </div>
+ {{ end }}
-{{ if ge .NextPage 0 }}
-<a href="?p={{ .NextPage}}">Next</a>
{{ end }}
{{ template "base.html" . }}
diff --git a/srv/src/post/post.go b/srv/src/post/post.go
index cadfcfc..3eab9bc 100644
--- a/srv/src/post/post.go
+++ b/srv/src/post/post.go
@@ -31,7 +31,7 @@ type Post struct {
ID string
Title string
Description string
- Tags []string
+ Tags []string // only alphanumeric supported
Series string
Body string
}
@@ -199,12 +199,13 @@ func (s *store) get(
query := fmt.Sprintf(
`SELECT
- p.id, p.title, p.description, p.series, pt.tag,
+ p.id, p.title, p.description, p.series, GROUP_CONCAT(pt.tag),
p.published_at, p.last_updated_at,
p.body
FROM posts p
LEFT JOIN post_tags pt ON (p.id = pt.post_id)
`+where+`
+ GROUP BY (p.id)
ORDER BY p.published_at %s, p.title %s`,
s.order, s.order,
)
@@ -243,18 +244,12 @@ func (s *store) get(
return nil, fmt.Errorf("scanning row: %w", err)
}
- if tag.Valid {
-
- if l := len(posts); l > 0 && posts[l-1].ID == post.ID {
- posts[l-1].Tags = append(posts[l-1].Tags, tag.String)
- continue
- }
+ post.Series = series.String
- post.Tags = append(post.Tags, tag.String)
+ if tag.String != "" {
+ post.Tags = strings.Split(tag.String, ",")
}
- post.Series = series.String
-
if publishedAt.Valid {
post.PublishedAt = time.Unix(publishedAt.Int64, 0).UTC()
}
diff --git a/srv/src/post/post_test.go b/srv/src/post/post_test.go
index c5587c8..db247d1 100644
--- a/srv/src/post/post_test.go
+++ b/srv/src/post/post_test.go
@@ -159,6 +159,8 @@ func TestStore(t *testing.T) {
h.testStoredPost(3),
}
+ posts[1].Tags = []string{"1", "2"}
+
for _, post := range posts {
assert.NoError(t, h.store.Set(post.Post, now))
}