This commit is contained in:
Alex Yatskov 2023-11-03 18:28:56 -07:00
parent 61b1dadb11
commit a0e2581f6b

View File

@ -273,18 +273,24 @@ func (self *Book) addVolume(newVolume *Volume) {
if currVolume == nil { if currVolume == nil {
insert(newVolume) insert(newVolume)
} else { } else {
switch newVolume.compare(currVolume) { switch currVolume.compare(newVolume) {
case 1: case 1:
insert(newVolume)
self.addOrphan(currVolume)
case -1:
self.addOrphan(newVolume) self.addOrphan(newVolume)
case -1:
self.addOrphan(currVolume)
insert(newVolume)
} }
} }
} }
func (self *Book) addOrphan(volume *Volume) { func (self *Book) addOrphan(newVolume *Volume) {
self.orphans = append(self.orphans, volume) for _, volume := range self.orphans {
if volume.compare(newVolume) == 0 {
return
}
}
self.orphans = append(self.orphans, newVolume)
} }
func (self *Book) parseVolumes(node *Node) { func (self *Book) parseVolumes(node *Node) {
@ -308,6 +314,10 @@ func (self *Book) parseVolumes(node *Node) {
} }
if len(volume.Pages) > 0 { if len(volume.Pages) > 0 {
sort.Slice(volume.Pages, func(i, j int) bool {
return strings.Compare(volume.Pages[i].Node.Name, volume.Pages[j].Node.Name) < 0
})
if index := parseVolumeIndex(node.Name); index != nil { if index := parseVolumeIndex(node.Name); index != nil {
volume.Index = *index volume.Index = *index
self.addVolume(volume) self.addVolume(volume)