Skip to content

Commit

Permalink
Handle absolute URLs in svg helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-kuendig committed Mar 7, 2019
1 parent 9141f49 commit c5c209a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions classes/svg/SVGInliner.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ public function __construct(string $themeDir)

public function inline(string $relPath, array $vars)
{
// If the path starts with a slash search relative to the base path.
// If the path starts with a slash search relative to the base path. If
// it starts with the app's host name make it relative.
$appUrl = trim(config('app.url'), '/');
if (starts_with($relPath, $appUrl)) {
$relPath = str_replace($appUrl, '', $relPath);
}

if (starts_with($relPath, '/')) {
$path = base_path($relPath);
} else {
Expand Down Expand Up @@ -61,4 +67,4 @@ protected function replaceVars(string $contents, array $vars = [])
{
return (new Twig)->parse($contents, $vars);
}
}
}
1 change: 1 addition & 0 deletions updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
2.0.4: Added `svg` helper function to inline SVGs (see README for usage)
2.0.5: Added missing relations for Theme and SVGInliner classes
2.0.6: Optimized image matching to also include images with custom attributes before the src attribute
2.0.7: Allow `| media` and `| theme` filters in the `svg` helper function

0 comments on commit c5c209a

Please sign in to comment.