summaryrefslogtreecommitdiff
path: root/src/gmi/tpl.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/gmi/tpl.go')
-rw-r--r--src/gmi/tpl.go44
1 files changed, 40 insertions, 4 deletions
diff --git a/src/gmi/tpl.go b/src/gmi/tpl.go
index 7aa1a2f..7959b8e 100644
--- a/src/gmi/tpl.go
+++ b/src/gmi/tpl.go
@@ -25,6 +25,11 @@ type rendererGetPostsRes struct {
HasMore bool
}
+type rendererGetPostSeriesNextPreviousRes struct {
+ Next *post.StoredPost
+ Previous *post.StoredPost
+}
+
type renderer struct {
url *url.URL
postStore post.Store
@@ -43,6 +48,41 @@ func (r renderer) GetPostByID(id string) (post.StoredPost, error) {
return p, nil
}
+func (r renderer) GetPostSeriesNextPrevious(p post.StoredPost) (rendererGetPostSeriesNextPreviousRes, error) {
+
+ seriesPosts, err := r.postStore.GetBySeries(p.Series)
+ if err != nil {
+ return rendererGetPostSeriesNextPreviousRes{}, fmt.Errorf(
+ "fetching posts for series %q: %w", p.Series, err,
+ )
+ }
+
+ var (
+ res rendererGetPostSeriesNextPreviousRes
+ foundThis bool
+ )
+
+ for i := range seriesPosts {
+
+ seriesPost := seriesPosts[i]
+
+ if seriesPost.ID == p.ID {
+ foundThis = true
+ continue
+ }
+
+ if !foundThis {
+ res.Next = &seriesPost
+ continue
+ }
+
+ res.Previous = &seriesPost
+ break
+ }
+
+ return res, nil
+}
+
func (r renderer) GetQueryValue(key, def string) string {
v := r.url.Query().Get(key)
if v == "" {
@@ -97,10 +137,6 @@ func (a *api) tplHandler() (gemini.Handler, error) {
r *gemini.Request,
) {
- if strings.HasSuffix(r.URL.Path, "/") {
- r.URL.Path += "index.gmi"
- }
-
tplPath := strings.TrimPrefix(r.URL.Path, "/")
ctx = mctx.Annotate(ctx,