dir: Sort by weight, date, and filepath

This commit is contained in:
adnano 2021-05-12 16:35:00 -04:00
parent 2a9691f947
commit 636a41126b

6
dir.go
View file

@ -274,10 +274,12 @@ func (d *Dir) write(dstDir string, task *Task) error {
return nil return nil
} }
// sort sorts the directory's pages by date. // sort sorts the directory's pages by weight, then date, then filepath.
func (d *Dir) sort() { func (d *Dir) sort() {
sort.Slice(d.Pages, func(i, j int) bool { sort.Slice(d.Pages, func(i, j int) bool {
return d.Pages[i].Date.After(d.Pages[j].Date) pi, pj := d.Pages[i], d.Pages[j]
return pi.Weight < pj.Weight || pi.Date.Before(pj.Date) ||
pi.FilePath < pj.FilePath
}) })
for i := range d.Pages { for i := range d.Pages {