-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move to custom API route for better compatiblity
- Loading branch information
Showing
11 changed files
with
141 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
use Kirby\Cms\App; | ||
use Kirby\Cms\Page; | ||
use Kirby\Cms\Site; | ||
use Kirby\Form\Form; | ||
use Kirby\Toolkit\Str; | ||
|
||
return [ | ||
'data' => [ | ||
'dirtyPageOrSite' => function (string $slug) { | ||
$kirby = kirby(); | ||
$page = $slug == 'site' ? $kirby->site() : $kirby->page(Str::replace($slug, '+', '/')); | ||
|
||
if ($this->requestBody()) { | ||
$form = Form::for($page, [ // Form class handles transformation of changed items | ||
'ignoreDisabled' => true, | ||
'input' => array_merge(['title' => $page->title()], $page->content()->data(), $this->requestBody()), | ||
'language' => $kirby->language()->code() | ||
]); | ||
|
||
$page = $page->clone(['content' => $form->data()]); | ||
} | ||
|
||
return $page; | ||
} | ||
], | ||
'routes' => [ | ||
[ | ||
'pattern' => '/k-seo/(:any)/heading-structure', | ||
'method' => 'POST', | ||
'action' => function (string $slug) { | ||
$model = $this->dirtyPageOrSite($slug); | ||
|
||
if ($model instanceof Page) { | ||
$page = $model->render(); | ||
$dom = new DOMDocument(); | ||
$dom->loadHTML(htmlspecialchars_decode(iconv('UTF-8', 'ISO-8859-1', htmlentities($page, ENT_COMPAT, 'UTF-8')), ENT_QUOTES), libxml_use_internal_errors(true)); | ||
|
||
$xpath = new DOMXPath($dom); | ||
$headings = $xpath->query('//h1|//h2|//h3|//h4|//h5|//h6'); | ||
$data = []; | ||
|
||
foreach ($headings as $heading) { | ||
$data[] = [ | ||
'level' => (int) str_replace('h', '', $heading->nodeName), | ||
'text' => $heading->textContent, | ||
]; | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
return null; | ||
} | ||
], | ||
[ | ||
'pattern' => '/k-seo/(:any)/seo-preview', | ||
'method' => 'POST', | ||
'action' => function (string $slug) { | ||
$model = $this->dirtyPageOrSite($slug); | ||
|
||
if ($model instanceof Site) { | ||
$model = $model->homePage(); | ||
} | ||
|
||
if ($model instanceof Page) { | ||
$meta = $model->metadata(); | ||
|
||
$ogImage = $meta->ogImage()->toFile()?->thumb([ | ||
'width' => 1200, | ||
'height' => 630, | ||
'crop' => true, | ||
]); | ||
|
||
return [ | ||
'page' => $model->slug(), | ||
'url' => $model->url(), | ||
'title' => $meta->title()->value(), | ||
'description' => $meta->metaDescription()->value(), | ||
'ogTitle' => $meta->ogTitle()->value(), | ||
'ogDescription' => $meta->ogDescription()->value(), | ||
'ogImage' => $ogImage?->url(), | ||
]; | ||
} | ||
|
||
return null; | ||
} | ||
] | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
return [ | ||
'seo-preview' => [ | ||
'mixins' => ['headline'], | ||
], | ||
'heading-structure' => [ | ||
'mixins' => ['headline'] | ||
] | ||
]; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.