|
|
|
@ -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, |
|
|
|
|