Skip to content

Commit

Permalink
Add EPUB fallbacks to resources
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu committed Sep 5, 2023
1 parent c695d2d commit 6ae32e6
Showing 1 changed file with 1 addition and 36 deletions.
37 changes: 1 addition & 36 deletions pkg/parser/epub/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ func (f PublicationFactory) Create() manifest.Manifest {
readingOrder = append(readingOrder, f.computeLink(item, []string{}))
}
}
readingOrderAllIds := f.computeIdsWithFallbacks(readingOrderIds)
var resourceItems []Item
for _, item := range mani {
if !extensions.Contains(readingOrderAllIds, item.ID) {
if !extensions.Contains(readingOrderIds, item.ID) {
resourceItems = append(resourceItems, item)
}
}
Expand Down Expand Up @@ -144,40 +143,6 @@ func mapEPUBLink(link EPUBLink) manifest.Link {
return l
}

// Recursively find the ids of the fallback items in [items]
func (f PublicationFactory) computeIdsWithFallbacks(ids []string) []string {
var fallbackIds []string
for _, id := range ids {
for _, v := range f.computeFallbackChain(id) {
if !extensions.Contains(fallbackIds, v) {
fallbackIds = append(fallbackIds, v)
}
}
}
return fallbackIds
}

// Compute the ids contained in the fallback chain of [item]
func (f PublicationFactory) computeFallbackChain(id string) []string {
// The termination has already been checked while computing links
var ids []string
item, ok := f.itemById[id]
if !ok {
return ids
}
if item.ID != "" {
ids = append(ids, item.ID)
}
if item.fallback != "" {
for _, v := range f.computeFallbackChain(item.fallback) {
if !extensions.Contains(ids, v) {
ids = append(ids, v)
}
}
}
return ids
}

// Compute a Publication [Link] for an epub [Item] and its fallbacks
func (f PublicationFactory) computeLink(item Item, fallbackChain []string) manifest.Link {
itemref, _ := f.itemrefByIdref[item.ID]
Expand Down

0 comments on commit 6ae32e6

Please sign in to comment.