From 87a127d04a4adc99ef1113d903efcce9cd7e4aa2 Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Sun, 16 Feb 2025 12:49:08 +0100 Subject: [PATCH] use epubimage format instead of global params --- internal/pkg/epubimage/epub_image.go | 5 +++++ internal/pkg/epubtemplates/content.go | 2 +- pkg/epuboptions/image.go | 4 ---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/pkg/epubimage/epub_image.go b/internal/pkg/epubimage/epub_image.go index 578e933..eb61663 100644 --- a/internal/pkg/epubimage/epub_image.go +++ b/internal/pkg/epubimage/epub_image.go @@ -73,6 +73,11 @@ func (i EPUBImage) EPUBImgPath() string { return "OEBPS/" + i.ImgPath() } +// MediaType of the epub image +func (i EPUBImage) MediaType() string { + return "image/" + i.Format +} + // ImgStyle style to apply to the image. // // center by default. diff --git a/internal/pkg/epubtemplates/content.go b/internal/pkg/epubtemplates/content.go index aa5483f..abd87f9 100644 --- a/internal/pkg/epubtemplates/content.go +++ b/internal/pkg/epubtemplates/content.go @@ -144,7 +144,7 @@ func (o Content) getManifest() []tag { var imageTags, pageTags, spaceTags []tag addTag := func(img epubimage.EPUBImage, withSpace bool) { imageTags = append(imageTags, - tag{"item", tagAttrs{"id": img.ImgKey(), "href": img.ImgPath(), "media-type": o.ImageOptions.MediaType()}, ""}, + tag{"item", tagAttrs{"id": img.ImgKey(), "href": img.ImgPath(), "media-type": img.MediaType()}, ""}, ) pageTags = append(pageTags, tag{"item", tagAttrs{"id": img.PageKey(), "href": img.PagePath(), "media-type": "application/xhtml+xml"}, ""}, diff --git a/pkg/epuboptions/image.go b/pkg/epuboptions/image.go index 1e78d1d..dc3f382 100644 --- a/pkg/epuboptions/image.go +++ b/pkg/epuboptions/image.go @@ -20,7 +20,3 @@ type Image struct { Format string `yaml:"format" json:"format"` AppleBookCompatibility bool `yaml:"apple_book_compatibility" json:"apple_book_compatibility"` } - -func (i Image) MediaType() string { - return "image/" + i.Format -}