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,15 +20,17 @@
<div class="details"> <div class="details">
<a class="user" href="{{ .Author.ProfileUrl }}">{{ .Author.Name }}</a> &mdash; {{ timehtml (relativedate .Date) .Date }} <a class="user" href="{{ .Author.ProfileUrl }}">{{ .Author.Name }}</a> &mdash; {{ timehtml (relativedate .Date) .Date }}
</div> </div>
<div class="overflow-hidden mh-5 mt2 relative"> {{ if $.ShowContent }}
<div> <div class="overflow-hidden mh-5 mt2 relative">
{{ .Content }} <div>
</div> {{ .Content }}
<div class="excerpt-fade absolute w-100 h4 bottom-0 z-999"></div> </div>
</div> <div class="excerpt-fade absolute w-100 h4 bottom-0 z-999"></div>
<div class="mt2"> </div>
<a href="{{ .Url }}">Read More &rarr;</a> <div class="mt2">
</div> <a href="{{ .Url }}">Read More &rarr;</a>
</div>
{{ end }}
</div> </div>
</div> </div>
{{ end }} {{ end }}

View File

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