Skip to content

Commit

Permalink
fix relative image for EPUB (on a custom work dir)
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-butti committed Sep 15, 2024
1 parent e84652a commit aff632f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/Commands/BuildEpubCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,25 @@ protected function buildEpub(
chapterData: $content_start . $chapter["html"] . $content_end,
externalReferences: EPub::EXTERNAL_REF_ADD,
);
foreach (Arr::get($chapter, "images", []) as $idxImage => $image) {
if (filter_var($image, FILTER_VALIDATE_URL)) {
foreach (Arr::get($chapter, "images", []) as $idxImage => $markdownPathImage) {
if (filter_var($markdownPathImage, FILTER_VALIDATE_URL)) {
continue;
}

if (! $this->isAbsolutePath($image)) {
$image = $this->config->contentPath . "/" . $image;
$pathImage = $markdownPathImage;
if (! $this->isAbsolutePath($markdownPathImage)) {
$pathImage = $this->config->contentPath . "/" . $markdownPathImage;
}

if (!file_exists($image)) {
if (!file_exists($pathImage)) {
continue;
}

$book->addLargeFile(
$image,
$markdownPathImage,
"image-" . $key . "-" . $idxImage,
$image,
mime_content_type($image),
$pathImage,
mime_content_type($pathImage),
);
}

Expand Down

0 comments on commit aff632f

Please sign in to comment.