From 69d91b469621ab2d9b2adf18db8d2c94b228fd5e Mon Sep 17 00:00:00 2001 From: Johann Schopplich Date: Mon, 6 Feb 2023 18:37:34 +0100 Subject: [PATCH] fix: resolve image image urls --- composer.lock | 10 ++-- site/plugins/kirby-vue-kit/classes/VueKit.php | 2 +- site/plugins/kirby-vue-kit/routes.php | 49 ++++++++++++++----- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/composer.lock b/composer.lock index 8e145590..85e7c474 100644 --- a/composer.lock +++ b/composer.lock @@ -209,16 +209,16 @@ }, { "name": "getkirby/cms", - "version": "3.9.0", + "version": "3.9.1", "source": { "type": "git", "url": "https://github.com/getkirby/kirby.git", - "reference": "066b0506a81fdd331edc54add601d907a61ebbb4" + "reference": "617a07aa0151aa4b1a3735b3b5e1a41ccc244a43" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/getkirby/kirby/zipball/066b0506a81fdd331edc54add601d907a61ebbb4", - "reference": "066b0506a81fdd331edc54add601d907a61ebbb4", + "url": "https://api.github.com/repos/getkirby/kirby/zipball/617a07aa0151aa4b1a3735b3b5e1a41ccc244a43", + "reference": "617a07aa0151aa4b1a3735b3b5e1a41ccc244a43", "shasum": "" }, "require": { @@ -305,7 +305,7 @@ "type": "custom" } ], - "time": "2023-01-17T12:55:18+00:00" + "time": "2023-01-31T10:07:31+00:00" }, { "name": "getkirby/composer-installer", diff --git a/site/plugins/kirby-vue-kit/classes/VueKit.php b/site/plugins/kirby-vue-kit/classes/VueKit.php index c8e84b2a..9bec7b89 100644 --- a/site/plugins/kirby-vue-kit/classes/VueKit.php +++ b/site/plugins/kirby-vue-kit/classes/VueKit.php @@ -4,8 +4,8 @@ use Exception; use Kirby\Data\Data; -use Kirby\Http\Url; use Kirby\Filesystem\F; +use Kirby\Http\Url; use Kirby\Toolkit\Html; class VueKit diff --git a/site/plugins/kirby-vue-kit/routes.php b/site/plugins/kirby-vue-kit/routes.php index bd52d9bd..c6a97821 100644 --- a/site/plugins/kirby-vue-kit/routes.php +++ b/site/plugins/kirby-vue-kit/routes.php @@ -1,8 +1,9 @@ "{$apiLocation}(:all).json", 'language' => '*', 'action' => function (...$args) { - if (kirby()->multilang()) { + $kirby = kirby(); + + if ($kirby->multilang()) { [$languageCode, $pageId] = $args; } else { [$pageId] = $args; } - $page = kirby()->page($pageId); + $page = $kirby->page($pageId); if (!$page || !$page->isVerified(get('token'))) { - $page = kirby()->site()->errorPage(); - }; + $page = $kirby->site()->errorPage(); + } $json = Page::render($page, 'json'); return Response::json($json); @@ -38,22 +41,42 @@ 'pattern' => '(:all)', 'language' => '*', 'action' => function (...$args) { - if (kirby()->multilang()) { - [$languageCode, $pageId] = $args; + $kirby = kirby(); + + if ($kirby->multilang()) { + [$languageCode, $path] = $args; } else { - [$pageId] = $args; + [$path] = $args; + } + + $extension = F::extension($path); + + // Try to resolve page and site files + if (!empty($extension)) { + $id = dirname($path); + $filename = basename($path); + + // Try to resolve image urls for pages and drafts + if ($page = $kirby->site()->findPageOrDraft($id)) { + return $page->file($filename); + } + + // Try to resolve site files at last + if ($file = $kirby->site()->file($filename)) { + return $file; + } } // Fall back to homepage id - if (empty($pageId)) { - $pageId = site()->homePageId(); + if (empty($path)) { + $path = site()->homePageId(); } - $page = kirby()->page($pageId); + $page = $kirby->page($path); if (!$page || !$page->isVerified(get('token'))) { - $page = kirby()->site()->errorPage(); - }; + $page = $kirby->site()->errorPage(); + } $html = Page::render($page, 'html'); return $html;