Skip to content

Commit 69d91b4

Browse files
fix: resolve image image urls
1 parent 1eda027 commit 69d91b4

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

composer.lock

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/plugins/kirby-vue-kit/classes/VueKit.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use Exception;
66
use Kirby\Data\Data;
7-
use Kirby\Http\Url;
87
use Kirby\Filesystem\F;
8+
use Kirby\Http\Url;
99
use Kirby\Toolkit\Html;
1010

1111
class VueKit

site/plugins/kirby-vue-kit/routes.php

+36-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22

3+
use JohannSchopplich\VueKit\Page;
34
use Kirby\Cms\Url;
5+
use Kirby\Filesystem\F;
46
use Kirby\Http\Response;
5-
use JohannSchopplich\VueKit\Page;
67

78
$apiLocation = Url::path(env('KIRBY_CONTENT_API_SLUG', ''), false, true);
89

@@ -14,17 +15,19 @@
1415
'pattern' => "{$apiLocation}(:all).json",
1516
'language' => '*',
1617
'action' => function (...$args) {
17-
if (kirby()->multilang()) {
18+
$kirby = kirby();
19+
20+
if ($kirby->multilang()) {
1821
[$languageCode, $pageId] = $args;
1922
} else {
2023
[$pageId] = $args;
2124
}
2225

23-
$page = kirby()->page($pageId);
26+
$page = $kirby->page($pageId);
2427

2528
if (!$page || !$page->isVerified(get('token'))) {
26-
$page = kirby()->site()->errorPage();
27-
};
29+
$page = $kirby->site()->errorPage();
30+
}
2831

2932
$json = Page::render($page, 'json');
3033
return Response::json($json);
@@ -38,22 +41,42 @@
3841
'pattern' => '(:all)',
3942
'language' => '*',
4043
'action' => function (...$args) {
41-
if (kirby()->multilang()) {
42-
[$languageCode, $pageId] = $args;
44+
$kirby = kirby();
45+
46+
if ($kirby->multilang()) {
47+
[$languageCode, $path] = $args;
4348
} else {
44-
[$pageId] = $args;
49+
[$path] = $args;
50+
}
51+
52+
$extension = F::extension($path);
53+
54+
// Try to resolve page and site files
55+
if (!empty($extension)) {
56+
$id = dirname($path);
57+
$filename = basename($path);
58+
59+
// Try to resolve image urls for pages and drafts
60+
if ($page = $kirby->site()->findPageOrDraft($id)) {
61+
return $page->file($filename);
62+
}
63+
64+
// Try to resolve site files at last
65+
if ($file = $kirby->site()->file($filename)) {
66+
return $file;
67+
}
4568
}
4669

4770
// Fall back to homepage id
48-
if (empty($pageId)) {
49-
$pageId = site()->homePageId();
71+
if (empty($path)) {
72+
$path = site()->homePageId();
5073
}
5174

52-
$page = kirby()->page($pageId);
75+
$page = $kirby->page($path);
5376

5477
if (!$page || !$page->isVerified(get('token'))) {
55-
$page = kirby()->site()->errorPage();
56-
};
78+
$page = $kirby->site()->errorPage();
79+
}
5780

5881
$html = Page::render($page, 'html');
5982
return $html;

0 commit comments

Comments
 (0)