Skip to content

Commit 6ae32e6

Browse files
committed
Add EPUB fallbacks to resources
1 parent c695d2d commit 6ae32e6

File tree

1 file changed

+1
-36
lines changed

1 file changed

+1
-36
lines changed

pkg/parser/epub/factory.go

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@ func (f PublicationFactory) Create() manifest.Manifest {
7373
readingOrder = append(readingOrder, f.computeLink(item, []string{}))
7474
}
7575
}
76-
readingOrderAllIds := f.computeIdsWithFallbacks(readingOrderIds)
7776
var resourceItems []Item
7877
for _, item := range mani {
79-
if !extensions.Contains(readingOrderAllIds, item.ID) {
78+
if !extensions.Contains(readingOrderIds, item.ID) {
8079
resourceItems = append(resourceItems, item)
8180
}
8281
}
@@ -144,40 +143,6 @@ func mapEPUBLink(link EPUBLink) manifest.Link {
144143
return l
145144
}
146145

147-
// Recursively find the ids of the fallback items in [items]
148-
func (f PublicationFactory) computeIdsWithFallbacks(ids []string) []string {
149-
var fallbackIds []string
150-
for _, id := range ids {
151-
for _, v := range f.computeFallbackChain(id) {
152-
if !extensions.Contains(fallbackIds, v) {
153-
fallbackIds = append(fallbackIds, v)
154-
}
155-
}
156-
}
157-
return fallbackIds
158-
}
159-
160-
// Compute the ids contained in the fallback chain of [item]
161-
func (f PublicationFactory) computeFallbackChain(id string) []string {
162-
// The termination has already been checked while computing links
163-
var ids []string
164-
item, ok := f.itemById[id]
165-
if !ok {
166-
return ids
167-
}
168-
if item.ID != "" {
169-
ids = append(ids, item.ID)
170-
}
171-
if item.fallback != "" {
172-
for _, v := range f.computeFallbackChain(item.fallback) {
173-
if !extensions.Contains(ids, v) {
174-
ids = append(ids, v)
175-
}
176-
}
177-
}
178-
return ids
179-
}
180-
181146
// Compute a Publication [Link] for an epub [Item] and its fallbacks
182147
func (f PublicationFactory) computeLink(item Item, fallbackChain []string) manifest.Link {
183148
itemref, _ := f.itemrefByIdref[item.ID]

0 commit comments

Comments
 (0)