Only show blog content preview in blog index when there are few posts

Partially resolves issue #30
This commit is contained in:
Asaf Gartner 2022-06-14 20:15:16 +03:00
parent 2012328436
commit 86a7128f25
2 changed files with 14 additions and 10 deletions

View File

@ -20,6 +20,7 @@
<div class="details">
<a class="user" href="{{ .Author.ProfileUrl }}">{{ .Author.Name }}</a> &mdash; {{ timehtml (relativedate .Date) .Date }}
</div>
{{ if $.ShowContent }}
<div class="overflow-hidden mh-5 mt2 relative">
<div>
{{ .Content }}
@ -29,6 +30,7 @@
<div class="mt2">
<a href="{{ .Url }}">Read More &rarr;</a>
</div>
{{ end }}
</div>
</div>
{{ end }}

View File

@ -30,11 +30,12 @@ func BlogIndex(c *RequestContext) ResponseData {
Posts []blogIndexEntry
Pagination templates.Pagination
ShowContent bool
CanCreatePost bool
NewPostUrl string
}
const postsPerPage = 5
const postsPerPage = 20
numThreads, err := hmndata.CountThreads(c.Context(), c.Conn, c.CurrentUser, hmndata.ThreadsQuery{
ProjectIDs: []int{c.CurrentProject.ID},
@ -105,6 +106,7 @@ func BlogIndex(c *RequestContext) ResponseData {
NextUrl: c.UrlContext.BuildBlog(utils.IntClamp(1, page+1, numPages)),
},
ShowContent: len(entries) <= 5,
CanCreatePost: canCreate,
NewPostUrl: c.UrlContext.BuildBlogNewThread(),
}, c.Perf)