From 5fc28c9b784474c1600bc1bdc23e7268869e5ca9 Mon Sep 17 00:00:00 2001 From: adnano Date: Wed, 12 May 2021 15:10:40 -0400 Subject: [PATCH] page: Add Prev and Next fields --- dir.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/dir.go b/dir.go index 912b5f8..52d66ce 100644 --- a/dir.go +++ b/dir.go @@ -32,6 +32,8 @@ type Page struct { Path string `yaml:"-"` Content string `yaml:"-"` Params map[string]string + Prev *Page `yaml:"-"` + Next *Page `yaml:"-"` } // NewDir returns a new Dir with the given path. @@ -263,6 +265,16 @@ func (d *Dir) sort() { sort.Slice(d.Pages, func(i, j int) bool { return d.Pages[i].Date.After(d.Pages[j].Date) }) + + for i := range d.Pages { + if i-1 > 0 { + d.Pages[i].Prev = d.Pages[i-1] + } + if i+1 < len(d.Pages) { + d.Pages[i].Next = d.Pages[i+1] + } + } + // Sort subdirectories for _, d := range d.Dirs { d.sort()