~adnano/kiln-devel

Fix post ordering by Weight, reversed Date and FilePath. v1 APPLIED

Ian M. Jones: 1
 Fix post ordering by Weight, reversed Date and FilePath.

 1 files changed, 11 insertions(+), 2 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~adnano/kiln-devel/patches/22799/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Fix post ordering by Weight, reversed Date and FilePath. Export this patch

---
Thanks for adding reverse date ordering of posts Adnan.

However, it didn't work for me, looks like the sort isn't linear
enough. So the sorts need to be run one after the other starting
with the least important and using SortStable to keep progress.

Hope this makes sense. I'm very new to Go, so if there's a more
efficient way of doing this, please reject this patch!

Also, thanks so much for kiln, it's great stuff.

 dir.go | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/dir.go b/dir.go
index d903761..e3437b1 100644
--- a/dir.go
+++ b/dir.go
@@ -262,8 +262,17 @@ func (d *Dir) write(dstDir string, task *Task) error {
func (d *Dir) sort() {
	sort.Slice(d.Pages, func(i, j int) bool {
		pi, pj := d.Pages[i], d.Pages[j]
		return pi.Weight < pj.Weight || pi.Date.After(pj.Date) ||
			pi.FilePath < pj.FilePath
		return pi.FilePath < pj.FilePath
	})

	sort.SliceStable(d.Pages, func(i, j int) bool {
		pi, pj := d.Pages[i], d.Pages[j]
		return pi.Date.After(pj.Date)
	})

	sort.SliceStable(d.Pages, func(i, j int) bool {
		pi, pj := d.Pages[i], d.Pages[j]
		return pi.Weight < pj.Weight
	})

	for i := range d.Pages {
-- 
2.17.1
Thanks!

To git@git.sr.ht:~adnano/kiln
   3667c41..820ab25  master -> master