edge/pkg/bundle/oldzim/favicon.go

50 lines
1.2 KiB
Go

package zim
import "github.com/pkg/errors"
func (z *ZimReader) Favicon() (*Article, error) {
illustration, err := z.getMetadataIllustration()
if err != nil && !errors.Is(err, ErrNotFound) {
return nil, errors.WithStack(err)
}
if illustration != nil {
return illustration, nil
}
namespaces := []string{"-", "I"}
entryNames := []string{"favicon", "favicon.png"}
for _, ns := range namespaces {
for _, en := range entryNames {
article, err := z.GetPageNoIndex(ns + "/" + en)
if err != nil && !errors.Is(err, ErrNotFound) {
return nil, errors.WithStack(err)
}
if article != nil {
return article, nil
}
}
}
return nil, errors.WithStack(ErrNotFound)
}
func (z *ZimReader) getMetadataIllustration() (*Article, error) {
metadata, err := z.Metadata(MetadataIllustration96x96at2, MetadataIllustration48x48at1)
if err != nil {
return nil, errors.WithStack(err)
}
if _, exists := metadata[MetadataIllustration96x96at2]; exists {
return z.GetPageNoIndex("M/" + string(MetadataIllustration96x96at2))
}
if _, exists := metadata[MetadataIllustration48x48at1]; exists {
return z.GetPageNoIndex("M/" + string(MetadataIllustration48x48at1))
}
return nil, errors.WithStack(ErrNotFound)
}