Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
fix: resolve image image urls
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Feb 6, 2023
1 parent 1eda027 commit 69d91b4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion site/plugins/kirby-vue-kit/classes/VueKit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 36 additions & 13 deletions site/plugins/kirby-vue-kit/routes.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use JohannSchopplich\VueKit\Page;
use Kirby\Cms\Url;
use Kirby\Filesystem\F;
use Kirby\Http\Response;
use JohannSchopplich\VueKit\Page;

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

Expand All @@ -14,17 +15,19 @@
'pattern' => "{$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);
Expand All @@ -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;
Expand Down

0 comments on commit 69d91b4

Please sign in to comment.