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()