-@BuildEbook.register('cover_thumb')
-@task(ignore_result=True)
-class BuildCoverThumb(BuildEbook):
- @classmethod
- def transform(cls, wldoc, fieldfile):
+ @staticmethod
+ def transform(wldoc):
+ # ugly, but we can't use wldoc.book_info here
+ from librarian import DCNS
+ url_elem = wldoc.edoc.getroot().find('.//' + DCNS('identifier.url'))
+ if url_elem is None:
+ gal_url = ''
+ gal_path = ''
+ else:
+ slug = url_elem.text.rstrip('/').rsplit('/', 1)[1]
+ gal_url = gallery_url(slug=slug)
+ gal_path = gallery_path(slug=slug)
+ return wldoc.as_html(gallery_path=gal_path, gallery_url=gal_url, base_url=absolute_url(gal_url))
+
+
+class CoverField(EbookField):
+ ext = 'jpg'
+ directory = 'cover'
+
+ @staticmethod
+ def transform(wldoc):
+ return wldoc.as_cover()
+
+ def set_file_permissions(self, fieldfile):
+ pass
+
+
+class CoverCleanField(CoverField):
+ directory = 'cover_clean'
+
+ @staticmethod
+ def transform(wldoc):
+ if wldoc.book_info.cover_box_position == 'none':
+ from librarian.cover import WLCover
+ return WLCover(wldoc.book_info, width=240).output_file()
+ from librarian.covers.marquise import MarquiseCover
+ return MarquiseCover(wldoc.book_info, width=240).output_file()
+
+
+class CoverThumbField(CoverField):
+ directory = 'cover_thumb'
+
+ @staticmethod
+ def transform(wldoc):