fix for #129 markdown images not found when base_url == '/' on homepage

This commit is contained in:
Andy Miller
2015-01-25 18:33:24 -07:00
parent f619c8f49f
commit 304c7519d1

View File

@@ -104,19 +104,20 @@ trait ParsedownGravTrait
//get the url and parse it
$url = parse_url(htmlspecialchars_decode($excerpt['element']['attributes']['src']));
$path_parts = pathinfo($url['path']);
// if there is no host set but there is a path, the file is local
if (!isset($url['host']) && isset($url['path'])) {
// get the local path to page media if possible
if (strpos($url['path'], $this->page->url()) !== false) {
if ($path_parts['dirname'] == $this->page->url()) {
$url['path'] = ltrim(str_replace($this->page->url(), '', $url['path']), '/');
// get the media objects for this page
$media = $this->page->media();
} else {
// see if this is an external page to this one
$path_parts = pathinfo($url['path']);
$page_route = str_replace($this->base_url, '', $path_parts['dirname']);
$ext_page = $this->pages->dispatch($page_route, true);
@@ -177,7 +178,7 @@ trait ParsedownGravTrait
}
} else {
// not a current page media file, see if it needs converting to relative
$excerpt['element']['attributes']['src'] = $this->convertUrl(Uri::build_url($url));
$excerpt['element']['attributes']['src'] = Uri::build_url($url);
}
}
}