Skip to content

Commit

Permalink
Fix epub building
Browse files Browse the repository at this point in the history
  • Loading branch information
fdambrine authored and artragis committed Jul 11, 2018
1 parent d82f86a commit a93f36a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 1 addition & 3 deletions zds/tutorialv2/epub_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,11 @@ def _(html_code):
final_path = splitted.path
elif image_url.startswith(settings.MEDIA_URL):
final_path = Path(image_url).name
elif Path(image_url).is_absolute():
elif Path(image_url).is_absolute() and 'images' in image_url:
root = Path(image_url)
while root.name != 'images':
root = root.parent
final_path = str(Path(image_url).relative_to(root))
if final_path.endswith('svg') or final_path.endswith('gif'):
final_path = final_path[:-3] + 'png'
image_path_in_ebook = relative_path + '/images/' + str(final_path).replace('%20', '_')
image['src'] = str(image_path_in_ebook)
ids = {}
Expand Down
3 changes: 2 additions & 1 deletion zds/tutorialv2/publication_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,14 @@ def publish(self, md_file_path, base_name, **kwargs):
try:
published_content_entity = self.get_published_content_entity(md_file_path)
epub_file_path = Path(base_name + '.epub')
logger.info('Start generating epub')
build_ebook(published_content_entity,
path.dirname(md_file_path),
epub_file_path)
except (IOError, OSError):
raise FailureDuringPublication('Error while generating epub file.')
else:
print(epub_file_path)
logger.info(epub_file_path)
epub_path = Path(published_content_entity.get_extra_contents_directory(), Path(epub_file_path.name))
if epub_path.exists():
os.remove(str(epub_path))
Expand Down

0 comments on commit a93f36a

Please sign in to comment.