Skip to content

Commit 0c5a018

Browse files
committed
feat: 'components' config syntax
1 parent 3004b25 commit 0c5a018

File tree

9 files changed

+50
-15
lines changed

9 files changed

+50
-15
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ index.dev.mjs
2727
/vendor/**/php4/*
2828
/vendor/getkirby/composer-installer
2929
i18n.cache
30+
31+
# happens because of installing the plugin as dev dependency
32+
site/plugins/kirby-queues

classes/Ai.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* Ai facade
1111
*/
12-
final class Ai
12+
class Ai
1313
{
1414
private static array $providers = [];
1515

classes/IndexNow.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace tobimori\Seo;
4+
5+
class IndexNow
6+
{
7+
}

config/fields.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Kirby\Cms\Page;
55
use Kirby\Http\Response;
66
use tobimori\Seo\Ai;
7+
use tobimori\Seo\Seo;
78

89
return [
910
'seo-writer' => [
@@ -13,7 +14,7 @@
1314
* Enables/disables the character counter in the top right corner
1415
*/
1516
'ai' => function (string|bool $ai = false) {
16-
if (!Ai::enabled()) {
17+
if (!Seo::option('components.ai')::enabled()) {
1718
return false;
1819
}
1920

@@ -37,8 +38,9 @@
3738
'method' => 'POST',
3839
'action' => function () {
3940
$kirby = $this->kirby();
41+
$component = Seo::option('components.ai');
4042

41-
if (!Ai::enabled()) {
43+
if (!$component::enabled()) {
4244
return Response::json([
4345
'status' => 'error',
4446
'message' => t('seo.ai.error.disabled')
@@ -100,7 +102,7 @@
100102

101103
try {
102104
foreach (
103-
Ai::streamTask($this->field()->ai(), [
105+
$component::streamTask($this->field()->ai(), [
104106
'instructions' => $data['instructions'] ?? null,
105107
'edit' => $data['edit'] ?? null
106108
]) as $chunk

config/options.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
<?php
22

33
use Kirby\Cms\Page;
4+
use tobimori\Seo\Meta;
45
use tobimori\Seo\Seo;
6+
use tobimori\Seo\Ai;
7+
use tobimori\Seo\IndexNow;
8+
use tobimori\Seo\SchemaSingleton;
59

610
return [
11+
// if you want to extend some of the built-in classes, you can overwrite them using the components config option
12+
// and page methods or similar stuff will adapt. full customizability!
13+
'components' => [
14+
'meta' => Meta::class,
15+
'ai' => Ai::class,
16+
'indexnow' => IndexNow::class,
17+
'schema' => SchemaSingleton::class,
18+
],
719
'cascade' => [
820
'fields',
921
'programmatic',
@@ -50,7 +62,10 @@
5062
'slack'
5163
],
5264
'robots' => [
53-
'active' => true, // whether robots handling should be done by the plugin
65+
'enabled' => true, // whether robots handling should be done by the plugin
66+
67+
// @deprecated - please use robots.enabled
68+
'active' => fn () => Seo::option('sitemap.enabled'),
5469
'followPageStatus' => true, // should unlisted pages be noindex by default?
5570
'pageSettings' => true, // whether to have robots settings on each page
5671
'index' => fn () => !option('debug'), // default site-wide robots setting
@@ -59,7 +74,9 @@
5974
'types' => ['index', 'follow', 'archive', 'imageindex', 'snippet'] // available robots types
6075
],
6176
'sitemap' => [
62-
'active' => true,
77+
'enabled' => true,
78+
// @deprecated - please use sitemap.enabled
79+
'active' => fn () => Seo::option('sitemap.enabled'),
6380
'redirect' => true, // redirect /sitemap to /sitemap.xml
6481
'locale' => 'en',
6582
'generator' => require __DIR__ . '/options/sitemap.php',
@@ -77,6 +94,12 @@
7794
'trailingSlash' => false, // whether to add trailing slashes to canonical URLs (except for files)
7895
],
7996
'ai' => require __DIR__ . '/options/ai.php',
97+
'indexnow' => [
98+
'enabled' => true,
99+
'searchEngine' => 'https://api.indexnow.org' // one will propagate to all others. so this is fine @see https://www.indexnow.org/faq
100+
// TODO: add batch job delay
101+
// TODO: add propagation thing (i.e. do not only submit the current page but a 'team member' page will always affect the 'team' page)
102+
],
80103
'generateSchema' => true, // whether to generate default schema.org data
81104
'locale' => 'en_US', // default locale, used for single-language sites
82105
'dateFormat' => null, // custom date format

config/page-methods.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

33
use Kirby\Cms\Language;
4-
use tobimori\Seo\Meta;
54
use tobimori\Seo\SchemaSingleton;
5+
use tobimori\Seo\Seo;
66

77
return [
8-
'schema' => fn ($type) => SchemaSingleton::getInstance($type, $this),
9-
'schemas' => fn () => SchemaSingleton::getInstances($this),
10-
'metadata' => fn (?Language $lang = null) => new Meta($this, $lang),
8+
'schema' => fn ($type) => Seo::option('components.schema')::getInstance($type, $this),
9+
'schemas' => fn () => Seo::option('components.schema')::getInstances($this),
10+
'metadata' => fn (?Language $lang = null) => new (Seo::option('components.meta'))($this, $lang),
1111
'robots' => fn (?Language $lang = null) => $this->metadata($lang)->robots(),
1212
'indexUrl' => function () {
1313
// Google: "fallback page for unmatched languages, especially on language/country selectors or auto-redirecting home pages."

config/site-methods.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
use Kirby\Http\Url;
44
use Kirby\Toolkit\Str;
5-
use tobimori\Seo\Meta;
6-
use tobimori\Seo\SchemaSingleton;
75
use tobimori\Seo\Seo;
86

97
return [
10-
'schema' => fn ($type) => SchemaSingleton::getInstance($type),
11-
'schemas' => fn () => SchemaSingleton::getInstances(),
12-
'lang' => fn () => Meta::normalizeLocale(Seo::option('default.locale', args: [$this->homePage()]), '-'),
8+
'schema' => fn ($type) => Seo::option('components.schema')::getInstance($type),
9+
'schemas' => fn () => Seo::option('components.schema')::getInstances(),
10+
'lang' => fn () => Seo::option('components.meta')::normalizeLocale(Seo::option('default.locale', args: [$this->homePage()]), '-'),
1311
'canonicalFor' => function (string $url, bool $useRootUrl = false) {
1412
// Determine the base URL
1513
$base = Seo::option('canonical.base', Seo::option('canonicalBase'));

vendor/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
'tobimori\\Seo\\Ai\\Drivers\\Anthropic' => $baseDir . '/classes/Ai/Drivers/Anthropic.php',
1818
'tobimori\\Seo\\Ai\\Drivers\\OpenAi' => $baseDir . '/classes/Ai/Drivers/OpenAi.php',
1919
'tobimori\\Seo\\Ai\\SseStream' => $baseDir . '/classes/Ai/SseStream.php',
20+
'tobimori\\Seo\\IndexNow' => $baseDir . '/classes/IndexNow.php',
2021
'tobimori\\Seo\\Meta' => $baseDir . '/classes/Meta.php',
2122
'tobimori\\Seo\\RobotsViewButton' => $baseDir . '/classes/RobotsViewButton.php',
2223
'tobimori\\Seo\\SchemaSingleton' => $baseDir . '/classes/SchemaSingleton.php',

vendor/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class ComposerStaticInit3e4bc37d480117d497c8333636c62d44
4040
'tobimori\\Seo\\Ai\\Drivers\\Anthropic' => __DIR__ . '/../..' . '/classes/Ai/Drivers/Anthropic.php',
4141
'tobimori\\Seo\\Ai\\Drivers\\OpenAi' => __DIR__ . '/../..' . '/classes/Ai/Drivers/OpenAi.php',
4242
'tobimori\\Seo\\Ai\\SseStream' => __DIR__ . '/../..' . '/classes/Ai/SseStream.php',
43+
'tobimori\\Seo\\IndexNow' => __DIR__ . '/../..' . '/classes/IndexNow.php',
4344
'tobimori\\Seo\\Meta' => __DIR__ . '/../..' . '/classes/Meta.php',
4445
'tobimori\\Seo\\RobotsViewButton' => __DIR__ . '/../..' . '/classes/RobotsViewButton.php',
4546
'tobimori\\Seo\\SchemaSingleton' => __DIR__ . '/../..' . '/classes/SchemaSingleton.php',

0 commit comments

Comments
 (0)