Skip to content

Commit

Permalink
add config option for single lang setups closes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
tobimori committed May 16, 2023
1 parent db13fd6 commit f855905
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 12 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ Add the meta snippet to your templates.

..and start defining your meta data in panel.

#### Single-Language Setup

If you're using a single-language setup, it's important to define the language code of your website in the config file:

```php
// config.php
return [
'tobimori.seo.lang' => 'en_US',
];
```

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.

### Schema.org usage

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.
Expand Down Expand Up @@ -133,6 +146,7 @@ This example shows an FAQ page with multiple blocks, each containing a question
| `generateSchema` | `true` | Whether to generate Schema.org JSON-LD with the default 'website' type |
| `canonicalIncludesWWW` | `false` | Whether to include the www. subdomain in the automatically generated canonical URL |
| `dateFormat` | `%Y-%m-%d` | Date format for generation of page modified meta tags |
| `lang` | `en_US` | Language code to be used in meta tags for single language setups |

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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "tobimori/kirby-seo",
"description": "The ultimate Kirby SEO toolkit",
"type": "kirby-plugin",
"version": "0.1.3",
"version": "0.2.0",
"license": "MIT",
"homepage": "https://github.com/tobimori/kirby-seo#readme",
"authors": [
Expand Down
3 changes: 1 addition & 2 deletions config/api.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use Kirby\Cms\App;
use Kirby\Cms\Page;
use Kirby\Cms\Site;
use Kirby\Form\Form;
Expand All @@ -16,7 +15,7 @@
$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()
'language' => $kirby->language()?->code()
]);

$page = $page->clone(['content' => $form->data()]);
Expand Down
6 changes: 4 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
'ogTemplate' => '{{ title }}',
'ogSiteName' => fn (Page $page) => $page->site()->title(),
'ogType' => 'website',
'ogLocale' => fn (Page $page) => $page->kirby()->language()->code() ?? 'en',
'twitterCardType' => 'summary',
'ogDescription' => fn (Page $page) => $page->metadata()->metaDescription(),
'twitterCreator' => fn (Page $page) => $page->metadata()->twitterSite(),
'lang' => fn (Page $page) => $page->kirby()->language()?->locale(LC_ALL) ?? $page->kirby()->option('tobimori.seo.lang', 'en_US'),
],
'socialMedia' => [
'twitter' => 'https://twitter.com/my-company',
Expand All @@ -32,7 +32,8 @@
],
'generateSchema' => true,
'canonicalIncludesWWW' => false,
'dateFormat' => '%Y-%m-%d'
'lang' => 'en_US',
'dateFormat' => '%Y-%m-%d',
],
'translations' => [
'de' => Yaml::decode(F::read(__DIR__ . '/translations/de.yml')),
Expand All @@ -43,6 +44,7 @@
'siteMethods' => [
'schema' => fn ($type) => SchemaSingleton::getInstance($type),
'schemas' => fn () => SchemaSingleton::getInstances(),
'lang' => fn () => option('tobimori.seo.default.lang')($this->homePage())
],
'pageMethods' => [
'schema' => fn ($type) => SchemaSingleton::getInstance($type, $this),
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "kirby-seo",
"description": "The ultimate Kirby SEO toolkit",
"version": "0.1.3",
"version": "0.2.0",
"private": true,
"license": "MIT",
"author": "Tobias Möritz",
"scripts": {
"dev": "kirbyup src/index.js --watch",
"build": "kirbyup src/index.js"
"build": "kirbyup src/index.js",
"prepare": "husky install"
},
"devDependencies": {
"husky": "^8.0.3",
Expand Down
4 changes: 3 additions & 1 deletion snippets/head.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
'og:image:height' => $ogImage?->height(),
'og:image:alt' => $ogImage?->alt(),
'og:type' => $meta->ogType(),
'og:locale' => $meta->ogLocale(),
];

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

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


<?php /** Robots */ ?>
<?php if ($page->status() == 'unlisted') : ?>
<meta name="robots" content="none">
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php return array(
'root' => array(
'name' => 'tobimori/kirby-seo',
'pretty_version' => '0.1.3',
'version' => '0.1.3.0',
'pretty_version' => '0.2.0',
'version' => '0.2.0.0',
'reference' => NULL,
'type' => 'kirby-plugin',
'install_path' => __DIR__ . '/../../',
Expand All @@ -29,8 +29,8 @@
'dev_requirement' => false,
),
'tobimori/kirby-seo' => array(
'pretty_version' => '0.1.3',
'version' => '0.1.3.0',
'pretty_version' => '0.2.0',
'version' => '0.2.0.0',
'reference' => NULL,
'type' => 'kirby-plugin',
'install_path' => __DIR__ . '/../../',
Expand Down

0 comments on commit f855905

Please sign in to comment.