From 6e42d9549e25ed16d3a3b491df8536821f7e2c36 Mon Sep 17 00:00:00 2001 From: Geert Plessers Date: Tue, 9 Sep 2025 11:09:25 +0200 Subject: [PATCH 1/5] change config values with values from statamic site variable --- src/Tags/AltSeo.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Tags/AltSeo.php b/src/Tags/AltSeo.php index 6a0fb44..c300f25 100644 --- a/src/Tags/AltSeo.php +++ b/src/Tags/AltSeo.php @@ -73,7 +73,7 @@ private function meta_array() 'og_image' => $this->getSocialImage(), 'twitter_card' => 'summary_large_image', - 'twitter_domain' => config('app.url'), + 'twitter_domain' => $this->context->value('site:url'), 'twitter_url' => $this->getCanonical(), 'twitter_title' => $this->getSocialTitle(), 'twitter_description' => strip_tags($this->getSocialDescription()), @@ -89,7 +89,7 @@ private function meta_array() */ public function replaceVars($string){ $blueprintPageTitle = $this->context->value('title'); // Page Title - $appName = $this->context->value('config.app.name'); // App Name + $appName = $this->context->value('site:name'); // App Name $string = str_replace('{title}', $blueprintPageTitle, $string); $string = str_replace('{site_name}', $appName, $string); return $string; @@ -112,7 +112,7 @@ public function getTitle() return $this->replaceVars($title); } - return $this->context->value('title') . ' | ' . $this->context->value('config.app.name'); + return $this->context->value('title') . ' | ' . $this->context->value('site:name'); } /** @@ -168,7 +168,7 @@ public function getSocialTitle() return $this->replaceVars($title); } - return $this->context->value('title') . ' | ' . $this->context->value('config.app.name'); + return $this->context->value('title') . ' | ' . $this->context->value('site:name'); } /** @@ -219,7 +219,7 @@ public function getSocialImage() $imageURL = str_replace('/assets/', '', $image); } } - $appUrl = config('app.url'); + $appUrl = $this->context->value('site:url'); if(!empty($imageURL) && !str_contains($imageURL, $appUrl)) { $imageURL = $appUrl . '/assets/' . $imageURL; } From 09c31e520c6b3d1bd68cde96715f4e3cc67eea98 Mon Sep 17 00:00:00 2001 From: Geert Plessers Date: Tue, 9 Sep 2025 11:30:47 +0200 Subject: [PATCH 2/5] fix multisite name and urls --- src/Tags/AltSeo.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Tags/AltSeo.php b/src/Tags/AltSeo.php index c300f25..fef3c90 100644 --- a/src/Tags/AltSeo.php +++ b/src/Tags/AltSeo.php @@ -73,7 +73,7 @@ private function meta_array() 'og_image' => $this->getSocialImage(), 'twitter_card' => 'summary_large_image', - 'twitter_domain' => $this->context->value('site:url'), + 'twitter_domain' => $this->context->value('site')->url, 'twitter_url' => $this->getCanonical(), 'twitter_title' => $this->getSocialTitle(), 'twitter_description' => strip_tags($this->getSocialDescription()), @@ -89,7 +89,7 @@ private function meta_array() */ public function replaceVars($string){ $blueprintPageTitle = $this->context->value('title'); // Page Title - $appName = $this->context->value('site:name'); // App Name + $appName = $this->context->value('site')->name; // App Name $string = str_replace('{title}', $blueprintPageTitle, $string); $string = str_replace('{site_name}', $appName, $string); return $string; @@ -112,7 +112,7 @@ public function getTitle() return $this->replaceVars($title); } - return $this->context->value('title') . ' | ' . $this->context->value('site:name'); + return $this->context->value('title') . ' | ' . $this->context->value('site')->name; } /** @@ -168,7 +168,7 @@ public function getSocialTitle() return $this->replaceVars($title); } - return $this->context->value('title') . ' | ' . $this->context->value('site:name'); + return $this->context->value('title') . ' | ' . $this->context->value('site')->name; } /** @@ -219,7 +219,7 @@ public function getSocialImage() $imageURL = str_replace('/assets/', '', $image); } } - $appUrl = $this->context->value('site:url'); + $appUrl = $this->context->value('site')->url; if(!empty($imageURL) && !str_contains($imageURL, $appUrl)) { $imageURL = $appUrl . '/assets/' . $imageURL; } From 22e2198e2c62c7e34b71aa0a15e7a2c84cd3c65e Mon Sep 17 00:00:00 2001 From: Geert Plessers Date: Tue, 9 Sep 2025 12:10:16 +0200 Subject: [PATCH 3/5] fixed the URL's for social images that are stored on other filesystem disks like s3 --- src/Tags/AltSeo.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Tags/AltSeo.php b/src/Tags/AltSeo.php index fef3c90..f7c1238 100644 --- a/src/Tags/AltSeo.php +++ b/src/Tags/AltSeo.php @@ -211,18 +211,33 @@ public function getSocialImage() { $imageURL = ''; if(!empty($this->context->value('alt_seo_social_image'))) { - $imageURL = str_replace('/assets/', '', Antlers::parse($this->context->value('alt_seo_social_image'))); + $imageURL = Antlers::parse($this->context->value('alt_seo_social_image')); } else { $data = new Data('settings'); if($data->get('alt_seo_social_image_default')) { $image = $data->get('alt_seo_social_image_default'); - $imageURL = str_replace('/assets/', '', $image); + $imageURL = $image; } } - $appUrl = $this->context->value('site')->url; - if(!empty($imageURL) && !str_contains($imageURL, $appUrl)) { - $imageURL = $appUrl . '/assets/' . $imageURL; + + // If the image is an absolute URL (e.g., S3), use it as is + if (preg_match('/^https?:\/\//', $image)) { + $imageURL = $image; + } else { + // Check if Statamic is configured to use S3 or local assets + $assetContainer = \Statamic\Facades\AssetContainer::findByHandle('assets'); + $disk = $assetContainer ? $assetContainer->disk() : null; + $assetBaseUrl = $assetContainer ? $assetContainer->url() : null; + + if ($disk && $assetBaseUrl && !empty($image)) { + // Remove leading slash if present + $image = ltrim($image, '/'); + $imageURL = rtrim($assetBaseUrl, '/') . '/' . $image; + } else { + $imageURL = str_replace('/assets/', '', $image); + } } + return $imageURL; } From 63b4cae7f556cb7ad035f7684a2af11ea6d56dbc Mon Sep 17 00:00:00 2001 From: Geert Plessers Date: Tue, 9 Sep 2025 13:20:18 +0200 Subject: [PATCH 4/5] fix bug with variable name --- src/Tags/AltSeo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tags/AltSeo.php b/src/Tags/AltSeo.php index f7c1238..c33197c 100644 --- a/src/Tags/AltSeo.php +++ b/src/Tags/AltSeo.php @@ -221,8 +221,8 @@ public function getSocialImage() } // If the image is an absolute URL (e.g., S3), use it as is - if (preg_match('/^https?:\/\//', $image)) { - $imageURL = $image; + if (preg_match('/^https?:\/\//', $imageURL)) { + return $imageURL; } else { // Check if Statamic is configured to use S3 or local assets $assetContainer = \Statamic\Facades\AssetContainer::findByHandle('assets'); From b0cd0b8d6d3be9eb318bfc278fd7aa2ff29dd4fa Mon Sep 17 00:00:00 2001 From: Geert Plessers Date: Tue, 9 Sep 2025 13:24:58 +0200 Subject: [PATCH 5/5] forgot to change second part --- src/Tags/AltSeo.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Tags/AltSeo.php b/src/Tags/AltSeo.php index c33197c..dc367ff 100644 --- a/src/Tags/AltSeo.php +++ b/src/Tags/AltSeo.php @@ -229,12 +229,12 @@ public function getSocialImage() $disk = $assetContainer ? $assetContainer->disk() : null; $assetBaseUrl = $assetContainer ? $assetContainer->url() : null; - if ($disk && $assetBaseUrl && !empty($image)) { + if ($disk && $assetBaseUrl && !empty($imageURL)) { // Remove leading slash if present - $image = ltrim($image, '/'); - $imageURL = rtrim($assetBaseUrl, '/') . '/' . $image; + $imageURL = ltrim($imageURL, '/'); + $imageURL = rtrim($assetBaseUrl, '/') . '/' . $imageURL; } else { - $imageURL = str_replace('/assets/', '', $image); + $imageURL = str_replace('/assets/', '', $imageURL); } }