mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 01:13:08 +00:00
page: Sort Dirs
This commit is contained in:
parent
250ff9131f
commit
5f16ca42d5
51
page.go
51
page.go
|
@ -286,29 +286,8 @@ func (p *Page) writeTo(dstPath string, task *Task) error {
|
|||
|
||||
// sort sorts the directory's pages by weight, then date, then filepath.
|
||||
func (p *Page) sort() {
|
||||
sort.Slice(p.Pages, func(i, j int) bool {
|
||||
pi, pj := p.Pages[i], p.Pages[j]
|
||||
return pi.FilePath < pj.FilePath
|
||||
})
|
||||
|
||||
sort.SliceStable(p.Pages, func(i, j int) bool {
|
||||
pi, pj := p.Pages[i], p.Pages[j]
|
||||
return pi.Date.After(pj.Date)
|
||||
})
|
||||
|
||||
sort.SliceStable(p.Pages, func(i, j int) bool {
|
||||
pi, pj := p.Pages[i], p.Pages[j]
|
||||
return pi.Weight < pj.Weight
|
||||
})
|
||||
|
||||
for i := range p.Pages {
|
||||
if i-1 >= 0 {
|
||||
p.Pages[i].Prev = p.Pages[i-1]
|
||||
}
|
||||
if i+1 < len(p.Pages) {
|
||||
p.Pages[i].Next = p.Pages[i+1]
|
||||
}
|
||||
}
|
||||
sortPages(p.Pages)
|
||||
sortPages(p.Dirs)
|
||||
|
||||
// Sort subdirectories
|
||||
for _, d := range p.Dirs {
|
||||
|
@ -316,6 +295,32 @@ func (p *Page) sort() {
|
|||
}
|
||||
}
|
||||
|
||||
func sortPages(pages []*Page) {
|
||||
sort.Slice(pages, func(i, j int) bool {
|
||||
pi, pj := pages[i], pages[j]
|
||||
return pi.FilePath < pj.FilePath
|
||||
})
|
||||
|
||||
sort.SliceStable(pages, func(i, j int) bool {
|
||||
pi, pj := pages[i], pages[j]
|
||||
return pi.Date.After(pj.Date)
|
||||
})
|
||||
|
||||
sort.SliceStable(pages, func(i, j int) bool {
|
||||
pi, pj := pages[i], pages[j]
|
||||
return pi.Weight < pj.Weight
|
||||
})
|
||||
|
||||
for i := range pages {
|
||||
if i-1 >= 0 {
|
||||
pages[i].Prev = pages[i-1]
|
||||
}
|
||||
if i+1 < len(pages) {
|
||||
pages[i].Next = pages[i+1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// execute runs a command.
|
||||
func execute(command string, input io.Reader, output io.Writer) error {
|
||||
split := strings.Split(command, " ")
|
||||
|
|
Loading…
Reference in a new issue