From c5c209a2f2675da52b7d9f572d0329791df5b660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20K=C3=BCndig?= Date: Thu, 7 Mar 2019 16:02:57 +0100 Subject: [PATCH] Handle absolute URLs in svg helper function --- classes/svg/SVGInliner.php | 10 ++++++++-- updates/version.yaml | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/classes/svg/SVGInliner.php b/classes/svg/SVGInliner.php index 9d3b449..9624672 100644 --- a/classes/svg/SVGInliner.php +++ b/classes/svg/SVGInliner.php @@ -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 { @@ -61,4 +67,4 @@ protected function replaceVars(string $contents, array $vars = []) { return (new Twig)->parse($contents, $vars); } -} \ No newline at end of file +} diff --git a/updates/version.yaml b/updates/version.yaml index e95fc78..bfde006 100644 --- a/updates/version.yaml +++ b/updates/version.yaml @@ -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