Skip to content

Commit f855905

Browse files
committed
add config option for single lang setups closes #6
1 parent db13fd6 commit f855905

File tree

7 files changed

+30
-12
lines changed

7 files changed

+30
-12
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ Add the meta snippet to your templates.
6464

6565
..and start defining your meta data in panel.
6666

67+
#### Single-Language Setup
68+
69+
If you're using a single-language setup, it's important to define the language code of your website in the config file:
70+
71+
```php
72+
// config.php
73+
return [
74+
'tobimori.seo.lang' => 'en_US',
75+
];
76+
```
77+
78+
It's used for the `og:locale` meta tag, and can be applied to the `lang` attribute of your `<html>` tag using the `$site->lang()` site method.
79+
6780
### Schema.org usage
6881

6982
The plugin exposes the [`spatie/schema-org`](https://github.com/spatie/schema-org) package as site & page methods, with a global store you can access anywhere.
@@ -133,6 +146,7 @@ This example shows an FAQ page with multiple blocks, each containing a question
133146
| `generateSchema` | `true` | Whether to generate Schema.org JSON-LD with the default 'website' type |
134147
| `canonicalIncludesWWW` | `false` | Whether to include the www. subdomain in the automatically generated canonical URL |
135148
| `dateFormat` | `%Y-%m-%d` | Date format for generation of page modified meta tags |
149+
| `lang` | `en_US` | Language code to be used in meta tags for single language setups |
136150

137151
Options allow you to fine tune the behaviour of the plugin. You can set them in your `config.php` file:
138152

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "tobimori/kirby-seo",
33
"description": "The ultimate Kirby SEO toolkit",
44
"type": "kirby-plugin",
5-
"version": "0.1.3",
5+
"version": "0.2.0",
66
"license": "MIT",
77
"homepage": "https://github.com/tobimori/kirby-seo#readme",
88
"authors": [

config/api.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
use Kirby\Cms\App;
43
use Kirby\Cms\Page;
54
use Kirby\Cms\Site;
65
use Kirby\Form\Form;
@@ -16,7 +15,7 @@
1615
$form = Form::for($page, [ // Form class handles transformation of changed items
1716
'ignoreDisabled' => true,
1817
'input' => array_merge(['title' => $page->title()], $page->content()->data(), $this->requestBody()),
19-
'language' => $kirby->language()->code()
18+
'language' => $kirby->language()?->code()
2019
]);
2120

2221
$page = $page->clone(['content' => $form->data()]);

index.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
'ogTemplate' => '{{ title }}',
1919
'ogSiteName' => fn (Page $page) => $page->site()->title(),
2020
'ogType' => 'website',
21-
'ogLocale' => fn (Page $page) => $page->kirby()->language()->code() ?? 'en',
2221
'twitterCardType' => 'summary',
2322
'ogDescription' => fn (Page $page) => $page->metadata()->metaDescription(),
2423
'twitterCreator' => fn (Page $page) => $page->metadata()->twitterSite(),
24+
'lang' => fn (Page $page) => $page->kirby()->language()?->locale(LC_ALL) ?? $page->kirby()->option('tobimori.seo.lang', 'en_US'),
2525
],
2626
'socialMedia' => [
2727
'twitter' => 'https://twitter.com/my-company',
@@ -32,7 +32,8 @@
3232
],
3333
'generateSchema' => true,
3434
'canonicalIncludesWWW' => false,
35-
'dateFormat' => '%Y-%m-%d'
35+
'lang' => 'en_US',
36+
'dateFormat' => '%Y-%m-%d',
3637
],
3738
'translations' => [
3839
'de' => Yaml::decode(F::read(__DIR__ . '/translations/de.yml')),
@@ -43,6 +44,7 @@
4344
'siteMethods' => [
4445
'schema' => fn ($type) => SchemaSingleton::getInstance($type),
4546
'schemas' => fn () => SchemaSingleton::getInstances(),
47+
'lang' => fn () => option('tobimori.seo.default.lang')($this->homePage())
4648
],
4749
'pageMethods' => [
4850
'schema' => fn ($type) => SchemaSingleton::getInstance($type, $this),

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "kirby-seo",
33
"description": "The ultimate Kirby SEO toolkit",
4-
"version": "0.1.3",
4+
"version": "0.2.0",
55
"private": true,
66
"license": "MIT",
77
"author": "Tobias Möritz",
88
"scripts": {
99
"dev": "kirbyup src/index.js --watch",
10-
"build": "kirbyup src/index.js"
10+
"build": "kirbyup src/index.js",
11+
"prepare": "husky install"
1112
},
1213
"devDependencies": {
1314
"husky": "^8.0.3",

snippets/head.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
'og:image:height' => $ogImage?->height(),
5252
'og:image:alt' => $ogImage?->alt(),
5353
'og:type' => $meta->ogType(),
54-
'og:locale' => $meta->ogLocale(),
5554
];
5655

5756
foreach ($mapOg as $property => $content) {
@@ -75,8 +74,11 @@
7574

7675
<link rel="alternate" hreflang="x-default" href="<?= $page->url($kirby->defaultLanguage()->code()) ?>">
7776
<meta property="og:locale" content="<?= $kirby->language()->locale(LC_ALL) ?>">
77+
<?php else : ?>
78+
<meta property="og:locale" content="<?= $meta->lang() ?>">
7879
<?php endif ?>
7980

81+
8082
<?php /** Robots */ ?>
8183
<?php if ($page->status() == 'unlisted') : ?>
8284
<meta name="robots" content="none">

vendor/composer/installed.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php return array(
22
'root' => array(
33
'name' => 'tobimori/kirby-seo',
4-
'pretty_version' => '0.1.3',
5-
'version' => '0.1.3.0',
4+
'pretty_version' => '0.2.0',
5+
'version' => '0.2.0.0',
66
'reference' => NULL,
77
'type' => 'kirby-plugin',
88
'install_path' => __DIR__ . '/../../',
@@ -29,8 +29,8 @@
2929
'dev_requirement' => false,
3030
),
3131
'tobimori/kirby-seo' => array(
32-
'pretty_version' => '0.1.3',
33-
'version' => '0.1.3.0',
32+
'pretty_version' => '0.2.0',
33+
'version' => '0.2.0.0',
3434
'reference' => NULL,
3535
'type' => 'kirby-plugin',
3636
'install_path' => __DIR__ . '/../../',

0 commit comments

Comments
 (0)