Skip to content

Commit

Permalink
small cascading fixes, fix twitterSite when field is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
tobimori committed May 9, 2023
1 parent 54a5c7a commit 58b6afd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
24 changes: 16 additions & 8 deletions classes/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ public function title()
$title = $this->metaTitle();
$template = $this->metaTemplate();

$useTemplate = $this->page->useTitleTemplate()->toBool() ?? true;
$string = $title;
$useTemplate = $this->page->useTitleTemplate();
$useTemplate = $useTemplate->isEmpty() ? true : $useTemplate->toBool();

$string = $title->value();
if ($useTemplate) {
$string = $this->page->toSafeString(
$template,
Expand All @@ -98,8 +100,10 @@ public function ogTitle()
$title = $this->metaTitle();
$template = $this->ogTemplate();

$useTemplate = $this->page->useOgTemplate()->toBool() ?? true;
$string = $title;
$useTemplate = $this->page->useOgTemplate();
$useTemplate = $useTemplate->isEmpty() ? true : $useTemplate->toBool();

$string = $title->value();
if ($useTemplate) {
$string = $this->page->toSafeString(
$template,
Expand All @@ -126,11 +130,15 @@ public function canonicalUrl()
public function twitterSite()
{
$accs = $this->page->site()->socialMediaAccounts()->toObject();
$username = '';

// tries to match all twitter urls, and extract the username
$matches = [];
preg_match('/^(https?:\/\/)?(www\.)?twitter\.com\/(#!\/)?@?(?<name>[^\/\?]*)$/', $accs->twitter()->value(), $matches);
if ($accs->twitter()->isNotEmpty()) {
// tries to match all twitter urls, and extract the username
$matches = [];
preg_match('/^(https?:\/\/)?(www\.)?twitter\.com\/(#!\/)?@?(?<name>[^\/\?]*)$/', $accs->twitter()->value(), $matches);
$username = $matches['name'];
}

return new Field($this->page, 'twitter', $matches['name'] ?? '');
return new Field($this->page, 'twitter', $username);
}
}
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.1",
"version": "0.1.2",
"license": "MIT",
"homepage": "https://github.com/tobimori/kirby-seo#readme",
"authors": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kirby-seo",
"description": "The ultimate Kirby SEO toolkit",
"version": "0.1.1",
"version": "0.1.2",
"private": true,
"license": "MIT",
"author": "Tobias Möritz",
Expand Down

0 comments on commit 58b6afd

Please sign in to comment.