mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 01:13:08 +00:00
page: Add Prev and Next fields
This commit is contained in:
parent
f68f86594b
commit
5fc28c9b78
12
dir.go
12
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()
|
||||
|
|
Loading…
Reference in a new issue